-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
식당 마커 클릭 시 식당정보 미리보기 구현 #197
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b8a6b02
chore: 지도 객체를 전역으로 관리하기 위한 저장소 생성 및 주석정리
junghyunbak 65dcd62
chore: restaurantRow 불필요한 import제거, box-shadow값 수정
junghyunbak c99056e
feat: 식당 미리보기 모달 컴포넌트 추가
junghyunbak 9e440c8
feat: MainMap 에 있던 컨트롤러 MainPage 로 이동작업
junghyunbak e83e543
fix: 상세보기 화면에서 이벤트 버블링 일으키는 문제 해결
junghyunbak edcc271
chore: 상수명 오타 수정
junghyunbak d31240a
Merge branch 'dev' into feat/#196
YuriKwon a477a4c
refactor: map controller 컴포넌트로 분리
junghyunbak 94d4a03
Merge branch 'feat/#196' of https://github.com/boostcampwm-2022/web08…
junghyunbak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import RestaurantRow from '@components/RestaurantRow'; | ||
import { AnimatePresence } from 'framer-motion'; | ||
import { useRestaurantDetailLayerStatusStore, useSelectedRestaurantDataStore } from '@store/index'; | ||
import { RESTAURANT_LIST_TYPES, RESTAURANT_DETAIL_TYPES } from '@constants/modal'; | ||
import { RestaurantPreviewBox, RestaurantPreviewLayout } from './styles'; | ||
|
||
function RestaurantPreview() { | ||
const modalRef = useRef<HTMLDivElement>(null); | ||
|
||
const { updateRestaurantDetailLayerStatus } = useRestaurantDetailLayerStatusStore( | ||
(state) => state | ||
); | ||
const { selectedRestaurantData, updateSelectedRestaurantData } = useSelectedRestaurantDataStore( | ||
(state) => state | ||
); | ||
|
||
useEffect(() => { | ||
const modalCloseWindowEvent = (e: Event) => { | ||
const { target } = e; | ||
|
||
if (modalRef.current && target instanceof HTMLElement && modalRef.current.contains(target)) { | ||
return; | ||
} | ||
|
||
updateSelectedRestaurantData(null); | ||
}; | ||
|
||
window.addEventListener('click', modalCloseWindowEvent); | ||
|
||
return () => { | ||
window.removeEventListener('click', modalCloseWindowEvent); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<RestaurantPreviewLayout ref={modalRef}> | ||
{selectedRestaurantData && ( | ||
<AnimatePresence> | ||
<RestaurantPreviewBox | ||
initial={{ opacity: 0, y: '100%' }} | ||
animate={{ opacity: 1, y: '0%' }} | ||
exit={{ opacity: 0, y: '100%' }} | ||
transition={{ | ||
duration: 0.5, | ||
}} | ||
onClick={() => { | ||
updateRestaurantDetailLayerStatus(RESTAURANT_DETAIL_TYPES.show); | ||
}} | ||
> | ||
<RestaurantRow | ||
restaurant={selectedRestaurantData} | ||
restaurantListType={RESTAURANT_LIST_TYPES.filtered} | ||
/> | ||
</RestaurantPreviewBox> | ||
</AnimatePresence> | ||
)} | ||
</RestaurantPreviewLayout> | ||
); | ||
} | ||
|
||
export default RestaurantPreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import styled from 'styled-components'; | ||
import * as palette from '@styles/Variables'; | ||
import { motion } from 'framer-motion'; | ||
|
||
export const RestaurantPreviewLayout = styled.div` | ||
z-index: ${palette.MAP_CONTROLLER_Z_INDEX}; | ||
`; | ||
|
||
export const RestaurantPreviewBox = styled(motion.div)` | ||
width: 100%; | ||
border-top-right-radius: 5px; | ||
border-top-left-radius: 5px; | ||
padding: 1% 3% 2% 3%; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ import { useEffect, useState, useRef } from 'react'; | |
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { io, Socket } from 'socket.io-client'; | ||
import { useSocketStore } from '@store/socket'; | ||
import { useMeetLocationStore, useRestaurantListLayerStatusStore } from '@store/index'; | ||
import { useMeetLocationStore, useRestaurantListLayerStatusStore, useMapStore } from '@store/index'; | ||
|
||
import { ReactComponent as GpsIcon } from '@assets/images/gps.svg'; | ||
import { ReactComponent as PointCircleIcon } from '@assets/images/point-circle.svg'; | ||
import { ReactComponent as CandidateListIcon } from '@assets/images/candidate-list.svg'; | ||
import { ReactComponent as ListIcon } from '@assets/images/list-icon.svg'; | ||
import { ReactComponent as MapIcon } from '@assets/images/map-icon.svg'; | ||
|
@@ -22,17 +24,21 @@ import RestaurantListLayer from '@components/RestaurantListLayer'; | |
import RestaurantDetailLayer from '@components/RestaurantDetailLayer'; | ||
import RestaurantCategory from '@components/RestaurantCategory'; | ||
import LoadingScreen from '@components/LoadingScreen'; | ||
import RestaurantPreview from '@components/RestaurantPreview'; | ||
|
||
import { apiService } from '@apis/index'; | ||
|
||
import { | ||
MapControlBox, | ||
ButtonInnerTextBox, | ||
CandidateListButton, | ||
CategoryBox, | ||
Header, | ||
HeaderBox, | ||
MainPageLayout, | ||
MapOrListButton, | ||
FooterBox, | ||
ControllerBox, | ||
} from './styles'; | ||
|
||
function MainPage() { | ||
|
@@ -43,14 +49,15 @@ function MainPage() { | |
const socketRef = useRef<Socket | null>(null); | ||
|
||
const { setSocket } = useSocketStore((state) => state); | ||
const { map } = useMapStore((state) => state); | ||
const { getCurrentLocation, updateUserLocation } = useCurrentLocation(); | ||
const { meetLocation, updateMeetLocation } = useMeetLocationStore(); | ||
|
||
const [isRoomConnect, setRoomConnect] = useState<boolean>(false); | ||
const [myId, setMyId] = useState<string>(''); | ||
const [myName, setMyName] = useState<string>(''); | ||
const [joinList, setJoinList] = useState<Map<UserIdType, UserType>>(new Map()); | ||
const [restaurantData, setRestaurantData] = useState<RestaurantType[]>([]); | ||
const { meetLocation, updateMeetLocation } = useMeetLocationStore(); | ||
|
||
const { restaurantListLayerStatus, updateRestaurantListLayerStatus } = | ||
useRestaurantListLayerStatusStore((state) => state); | ||
|
@@ -196,20 +203,63 @@ function MainPage() { | |
<RestaurantCategory /> | ||
</CategoryBox> | ||
|
||
{/* 식당 후보 목록 <-> 지도 화면 */} | ||
{/* 식당 후보 목록 <-- 전체 식당 목록 */} | ||
<CandidateListButton onClick={handleSwitchCandidateList}> | ||
{isRestaurantCandidateList() ? <MapLocationIcon /> : <CandidateListIcon />} | ||
</CandidateListButton> | ||
|
||
{/* 전체 식당 목록 <-> 지도 화면 */} | ||
{/* 전체 식당 목록 <-- 식당 후보 목록 */} | ||
<MapOrListButton onClick={handleSwitchRestaurantList}> | ||
{isRestaurantFilteredList() ? <MapIcon /> : <ListIcon />} | ||
<ButtonInnerTextBox> | ||
{isRestaurantFilteredList() ? '지도보기' : '목록보기'} | ||
</ButtonInnerTextBox> | ||
</MapOrListButton> | ||
<FooterBox> | ||
<ControllerBox> | ||
{/* 식당 후보 목록 <-> 지도 화면 */} | ||
{/* 식당 후보 목록 <-- 전체 식당 목록 */} | ||
<CandidateListButton onClick={handleSwitchCandidateList}> | ||
{isRestaurantCandidateList() ? <MapLocationIcon /> : <CandidateListIcon />} | ||
</CandidateListButton> | ||
|
||
{/* 전체 식당 목록 <-> 지도 화면 */} | ||
{/* 전체 식당 목록 <-- 식당 후보 목록 */} | ||
<MapOrListButton onClick={handleSwitchRestaurantList}> | ||
{isRestaurantFilteredList() ? <MapIcon /> : <ListIcon />} | ||
<ButtonInnerTextBox> | ||
{isRestaurantFilteredList() ? '지도보기' : '목록보기'} | ||
</ButtonInnerTextBox> | ||
</MapOrListButton> | ||
|
||
<MapControlBox> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
if (!map || !meetLocation) { | ||
return; | ||
} | ||
|
||
map.setCenter(meetLocation); | ||
}} | ||
> | ||
<PointCircleIcon /> | ||
</button> | ||
<button | ||
type="button" | ||
onClick={async () => { | ||
const socket = socketRef.current; | ||
|
||
if (!(socket instanceof Socket)) { | ||
return; | ||
} | ||
|
||
const location = await getCurrentLocation(); | ||
socket.emit('changeMyLocation', { userLat: location.lat, userLng: location.lng }); | ||
updateUserLocation(location); | ||
|
||
if (!map) { | ||
return; | ||
} | ||
|
||
map.setCenter(location); | ||
}} | ||
> | ||
<GpsIcon /> | ||
</button> | ||
</MapControlBox> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 얘를 별도 컴포넌트로 분리하는게 좋을 것 같습니다. |
||
</ControllerBox> | ||
|
||
<RestaurantPreview /> | ||
</FooterBox> | ||
|
||
{/* 식당 리스트 & 식당 상세정보 Full-Screen 모달 컴포넌트 */} | ||
<RestaurantListLayer restaurantData={restaurantData} /> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
궁금한게 Map 을 전역 상태로 하나 더 생성하셨더라구요. 그러면 컴포넌트에 굳이 mapRef를 따로 생성하는게 의미가 있는지 궁금합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀하신대로 불필요해서 수정해야 할 부분입니다. 일단 기능 구현이 목적이었기 때문에 useNaverMaps훅 내부에 있는 로직을 MainMap 안에 다시 옮기는 작업을 하지 않았습니다. 😓