Skip to content

Commit

Permalink
Merge pull request #27 from Ravende/connectBE
Browse files Browse the repository at this point in the history
[FE] Card (카페 리스트) 백엔드 연동 완료 및 css 조정 완료
  • Loading branch information
Ravende authored Feb 22, 2024
2 parents 37b2185 + cacc4fd commit 801bc8b
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 45 deletions.
30 changes: 20 additions & 10 deletions frontend/src/card/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ export function Card() {
movePage('/cardinfo');
}
const [cafeDataList, setCafeDataList] = useState([]);
const getToday = () => {
const days = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'];
const todayIndex = new Date().getDay(); // 0부터 일요일, 1부터 월요일, ..., 6부터 토요일
return days[todayIndex];
};
const today = getToday();

useEffect(() => {
// Replace 'your-backend-url' with the actual URL of your backend service
axios.get('https://echubserver.shop:8080/api/cafe') // Updated endpoint
axios
.get('https://echubserver.shop:8080/api/cafe') // Updated endpoint
.then(response => {
console.log('Cafe Data:', response.data);
setCafeDataList(response.data); // Assuming the response is a list of cafes
})
.catch(error => {
Expand All @@ -24,22 +32,24 @@ export function Card() {

return (
<div>

{cafeDataList.map(cafeData => (

<div key={cafeData.cafeId} className="cafe-box">
<button className="cafe-name" onClick={gopage}>{cafeData.cafeName}</button>
<p className="operating-hours">
{`영업시간: ${cafeData.businessHour.opening_time} - ${cafeData.businessHour.closing_time}`}
<button className="cafe-name" onClick={gopage}>
{cafeData.cafeName}
</button>
<p className="operating-hours">{`영업시간: ${cafeData.businessHour[today] || '-'} `}</p>
<p className="operating-state" style={{ color: cafeData.businessStatus === '영업 중' ? 'blue' : 'red' }}>
{cafeData.businessStatus === '영업 중' ? '| 영업중' : '| 영업종료'}
</p>
<p className="operating-state" style={{ color: 'blue' }}>
{cafeData.businessStatus}
<p className="menu" style={{ fontSize: '17px' }}>
{cafeData.address}
</p>
<p className="menu">대표메뉴: {cafeData.bestmenu}</p>

<div className="hash-warp">
{cafeData.hashtag.map(tag => (
<div key={tag} className="hash">{tag}</div>
<div key={tag} className="hash">
{tag}
</div>
))}
</div>
<div className="cafe-image">
Expand Down
41 changes: 19 additions & 22 deletions frontend/src/card/card.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,36 @@
position: relative;
background-color: #fff;
width: 92%;
height: 300px;
height: fit-content;
min-height: min-content;
max-height: max-content;
padding: 10px;
margin-top: 40px;
background-color: #84a6352c;
border-radius: 10px;
box-shadow: 5px 8px 3px rgba(0, 0, 0, 0.5);
/* text-align: center;
display: flex;
flex-direction: column;
justify-content: center; */
/*justify-content: center; */
}

.cafe-name {
font-size: 28px;
font-size: 20px;
position: absolute;
width:270px;
height:auto;
text-shadow: #000000;
width: 260px;
height: auto;
top: 17px;
left: -10px;
left: 15px;
font-weight: bold;
text-align: center;
color: #fff;
transform: translate(10%, 30%);
background-color: #419764;
border-radius: 15px;
border-color: #666;
color: #333;
background-color: #84a6352c;
}

.operating-hours,
.operating-state,
.menu {
position: relative;
top: 80px;
top: 55px;
margin-top: 10px;
margin: 20px;
margin-left: 10px;
font-size: 20px;
Expand All @@ -49,9 +45,9 @@
#cafeimg {
position: absolute;
left: 290px;
top: 20px;
width: 120px;
height: 170px;
top: 18px;
width: 115px;
height: 165px;
border-radius: 30px;
}

Expand All @@ -61,7 +57,7 @@
font-size: 15.5px;
color: #fff;
padding: 8px;
top: 78px;
top: 60px;
margin: 5px;
width: 155px;
height: 20px;
Expand All @@ -73,8 +69,9 @@

.hash-warp {
display: flex;
margin: 10px 0;
flex-wrap: wrap;
justify-content: center;
margin-top: 10px;
margin-bottom: 60px;
}


34 changes: 27 additions & 7 deletions frontend/src/cardInfo/CardInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import '../App.css';
import './cardInfo.css';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Review } from '../review';
import { Write } from '../write';
import { Menu } from '../menu';
import '../App.css';
import './cardInfo.css';

export function CardInfo() {
const movePage = useNavigate();
const [activeComponent, setActiveComponent] = useState('review');

function gopage() {
const goPage = () => {
movePage('/');
}
};

const goReview = () => {
setActiveComponent('review');
};

const goWrite = () => {
setActiveComponent('write');
};

return (
<div className="cafeinfo-box">
<button onClick={gopage}>
<button onClick={goPage}>
<img id="back_icon" alt="back" src="./assets/back_icon.png" />
</button>

Expand All @@ -30,8 +40,18 @@ export function CardInfo() {
</div>
<div id="operating-hours">평일 12:0~22:00 / 주말 11:00~22:00</div>

<Review />
<Write />
{activeComponent === 'review' && <Review />}
{activeComponent === 'write' && <Write />}

<div>
<button className="write_button" onClick={goReview}>
리뷰 보기
</button>
<button className="write_button" onClick={goWrite}>
글쓰기
</button>
</div>

<Menu />
</div>
);
Expand Down
92 changes: 92 additions & 0 deletions frontend/src/map/Infowindow.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const data = [];
const m_infos = [];
const positions = [];

axios
.get('https://echubserver.shop:8080/api/cafe/search?q={keyword}')
.then(response => {
console.log('Cafe Data:', response.data);
setCafeDataInfo(response.data); // Assuming the response is a list of cafes

for (let i = 0; i < data.length; i++) {
let m_g = data[i].place_name;
let m_a = data[i].address_name;
let m_x = data[i].x;
let m_y = data[i].y;

let m_infos = { 카페명: m_g, 카페주소: m_a, 카페경도: m_x, 카페위도: m_y };
m_infos.push(m_info);
}

// 아래는 마커와 인포윈도우 여러개 표시
for (let i = 0; i < m_infos.length; i++) {
let cafeName = m_infos[i].place_name;
let m_i_x = m_infos[i].x;
let m_i_y = m_infos[i].y;
let m_a = m_infos[i].address_name;

var gb_position = {
content: (
<div key={cafeData.cafeId} className="InfoWindow">
<h3 style={{ lineHeight: '2.0' }}>{cafeName}</h3>
<p style={{ lineHeight: '1.0' }}>
${cafeData.businessHour.opening_time} - ${cafeData.businessHour.closing_time}
</p>
<p style={{ lineHeight: '1.8', color: 'blue' }}>{cafeData.businessStatus}</p>
</div>
),
latlng: new kakao.maps.LatLng(Lat, Lng),
};
positions.push(gb_position);
}

for (var i = 0; i < positions.length; i++) {
var m_i_addr2 = m_infos[i]['매장주소'];
var m_i_name2 = m_infos[i]['매장명'];

var marker = new kakao.maps.Marker({
map: map,
position: positions[i].latlng,
clickable: true,
});
var iwContent = `<div id="iw_con_info"><h5>${m_i_name2}</h5><h5>${m_i_addr2}</h5><h5>권역: ${m_i_gw2}</h5><h5>거점: ${m_i_gj2}</h5></div>`, // 인포윈도우에 표출될 내용으로 HTML 문자열이나 document element가 가능합니다
iwRemoveable = true; // removeable 속성을 ture 로 설정하면 인포윈도우를 닫을 수 있는 x버튼이 표시됩니다

var infowindow = new kakao.maps.InfoWindow({
content: iwContent,
removable: iwRemoveable,
});

kakao.maps.event.addListener(marker, 'click', makeOverListener(map, marker, infowindow));
}
})
.catch(error => {
console.error('Error fetching cafe data:', error);
});

// 인포윈도우를 표시하는 클로저를 만드는 함수
function makeOverListener(map, marker, infowindow) {
return function () {
infowindow.open(map, marker);
};
}
// 인포윈도우를 닫는 클로저를 만드는 함수
function makeOutListener(infowindow) {
return function () {
infowindow.close();
};
}

// return (
// <div>
// {cafeDataInfo.map(cafeData => (
// <div key={cafeData.cafeId} className="InfoWindow">
// <h3 style={{ lineHeight: '2.0' }}>{cafeData.cafeName}</h3>
// <p style={{ lineHeight: '1.0' }}>
// {`${cafeData.businessHour.opening_time} - ${cafeData.businessHour.closing_time}`}
// </p>
// <p style={{ lineHeight: '1.8', color: 'blue' }}>{cafeData.businessStatus}</p>
// </div>
// ))}
// </div>
// );
37 changes: 31 additions & 6 deletions frontend/src/map/KakaoMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useEffect, useRef, useState } from 'react';
import { Map, MapMarker } from 'react-kakao-maps-sdk';
import './map.css';
import useKakaoLoader from './useKakaoLoader.jsx';
import axios from 'axios';
import { useNavigate } from 'react-router-dom';

export default function KakaoMap() {
useKakaoLoader();
Expand All @@ -28,16 +30,32 @@ export default function KakaoMap() {
map.setLevel(map.getLevel() + 1);
};

/* 마커 라우팅 */
const movePage = useNavigate();
function gopage() {
movePage('/cardinfo');
}
const [cafeDataInfo, setCafeDataInfo] = useState([]);

/* 장소 검색 */
useEffect(() => {
axios
.get('https://echubserver.shop:8080/api/cafe/search?q={keyword}') // Updated endpoint
.then(response => {
console.log('Cafe Data:', response.data);
setCafeDataInfo(response.data); // Assuming the response is a list of cafes
})
.catch(error => {
console.error('Error fetching cafe data:', error);
});

if (!map) return;
const ps = new window.kakao.maps.services.Places();

// 키워드 검색 완료 시 호출되는 콜백함수
const placesSearchCB = (data, status) => {
if (status === window.kakao.maps.services.Status.OK) {
// 검색된 장소 위치를 기준으로 지도 범위를 재설정하기위해
// LatLngBounds 객체에 좌표를 추가합니다
// 검색된 장소 위치를 기준으로 지도 범위 재설정 (LatLngBounds 객체에 좌표 추가)
const bounds = new window.kakao.maps.LatLngBounds();
const markers = [];

Expand All @@ -53,20 +71,26 @@ export default function KakaoMap() {
}
setMarkers(markers);

// 검색된 장소 위치를 기준으로 지도 범위를 재설정합니다
// 검색된 장소 위치를 기준으로 지도 범위 재설정
map.setBounds(bounds);
}
};

// 키워드 검색
ps.keywordSearch('카페', placesSearchCB, {
radius: 1000,
radius: 20000,
location: new window.kakao.maps.LatLng(lat, lng),
size: 15,
page: 1,
rect: '126.942065,37.562414,126.948871,37.557108',
});
// 카테고리 검색 - 카페: CE7
ps.categorySearch('CE7', placesSearchCB, {
radius: 1000,
radius: 20000,
location: new window.kakao.maps.LatLng(lat, lng),
size: 15,
page: 1,
rect: '126.942065,37.562414,126.948871,37.557108',
});
}, [map, lat, lng]);

Expand Down Expand Up @@ -97,14 +121,15 @@ export default function KakaoMap() {
<img src="https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/ico_minus.png" alt="축소" />
</span>
</div>

{/* 마커 생성 */}
{markers.map(marker => (
<MapMarker
key={`marker-${marker.content}-${marker.position.lat},${marker.position.lng}`}
position={marker.position}
removable={true}
clickable={true}
// onClick={() => setInfo(marker)} // 클릭 이벤트
onClick={() => gopage()} // 클릭 이벤트
onMouseOver={() => {
setIsOpen(true);
setInfo(marker);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/sideBar/sideBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ aside {
overflow-y: auto;
flex-shrink: 0;
max-height: 800px;
pointer-events: auto;
}

#side {
Expand Down

0 comments on commit 801bc8b

Please sign in to comment.