Skip to content

Commit

Permalink
Refactor: 지역 슬라이드 이동 시 추천 장소 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
goeun208 committed Mar 15, 2024
1 parent 5720cef commit 12b52d8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/components/main/Recommendation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Recommendation = (props: GetGroupBestRegionListRes) => {
latitude={item.latitude}
longitude={item.longitude}
moveUserInfo={item.moveUserInfo}
index={data.indexOf(item)}
/>
</div>
))}
Expand Down
9 changes: 8 additions & 1 deletion src/components/main/RecommendationItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { useSetRecoilState } from 'recoil';
import AdminBox from '../common/main/AdminBox';
import OthersBox from '../common/main/OthersBox';
import { GetGroupBestRegionProps, GetUserInfoProps } from '@/types/SpaceType';
import { recommendIndexAtom } from '@/states/recommendIndexAtom';
import { useEffect } from 'react';

const RecommendationItem = ({ name, moveUserInfo }: GetGroupBestRegionProps) => {
const RecommendationItem = ({ name, moveUserInfo, index }: GetGroupBestRegionProps) => {
console.log(moveUserInfo);
const setRecommendIndex = useSetRecoilState(recommendIndexAtom);
const adminUser: GetUserInfoProps[] = moveUserInfo.filter((item) => item.isAdmin);
// console.log(adminUser);
const defaultUser: GetUserInfoProps[] = moveUserInfo.filter((item) => !item.isAdmin);
useEffect(() => {
setRecommendIndex(index);
}, [index, setRecommendIndex]);
return (
<div className="flex flex-col justify-center items-center">
<div className="rounded-tl-lg rounded-tr-lg pt-6 pl-10 bg-main_orange w-[1200px] h-[84px] ">
Expand Down
23 changes: 14 additions & 9 deletions src/components/main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { userNavAtom } from '@/states/userNavAtom';
import React, { useEffect, useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { NAV_LIST } from '../common/navbar/Navigation';
import ShareButton from '../common/button/share';
import Recommendation from './Recommendation';
Expand All @@ -11,6 +11,7 @@ import { useGetGroup } from '@/hooks/useGetGroup';
import KakaoMap from './KakaoMap';
import { groupIdAtom } from '@/states/groupIdAtom';
import LoadingPage from '@/pages/loading';
import { recommendIndexAtom } from '@/states/recommendIndexAtom';

interface MainProps {
id: string;
Expand Down Expand Up @@ -39,6 +40,7 @@ const Main = ({ id }: MainProps) => {

const setUserAtom = useSetRecoilState(userNavAtom);
setUserAtom({ activeNavType: NAV_LIST.MAIN });
const recommendIndex = useRecoilValue(recommendIndexAtom);
const [groupData, setGroupData] = useState<any>();
const [groupNameData, setGroupNameData] = useState<any>();

Expand All @@ -49,14 +51,17 @@ const Main = ({ id }: MainProps) => {
useEffect(() => {
console.log(gData, 'gData');
groupData !== gData && setGroupData(gData);
}, [gData, groupData]);

useEffect(() => {
if (groupData) {
setLat(groupData?.data[0].latitude);
setLng(groupData?.data[0].longitude);
setLocal(groupData?.data[0].name);
setUserPath(groupData?.data[0].moveUserInfo.filter((item: any) => item.userId === userId));
setOtherUserPath(groupData?.data[0].moveUserInfo.filter((item: any) => item.userId !== userId));
setLat(groupData?.data[recommendIndex].latitude);
setLng(groupData?.data[recommendIndex].longitude);
setLocal(groupData?.data[recommendIndex].name);
setUserPath(groupData?.data[recommendIndex].moveUserInfo.filter((item: any) => item.userId === userId));
setOtherUserPath(groupData?.data[recommendIndex].moveUserInfo.filter((item: any) => item.userId !== userId));
}
}, [gData, groupData]);
}, [groupData, recommendIndex, userId]);

useEffect(() => {
console.log(gNameData, 'gNameData');
Expand Down Expand Up @@ -86,8 +91,8 @@ const Main = ({ id }: MainProps) => {

{userPath && otherUserPath && (
<KakaoMap
lat={parseFloat(groupData?.data[0].latitude.toString() as string)}
lng={parseFloat(groupData?.data[0].longitude.toString() as string)}
lat={parseFloat(groupData?.data[recommendIndex].latitude.toString() as string)}
lng={parseFloat(groupData?.data[recommendIndex].longitude.toString() as string)}
user={userPath}
otherUser={otherUserPath}
/>
Expand Down
6 changes: 6 additions & 0 deletions src/states/recommendIndexAtom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { atom } from 'recoil';

export const recommendIndexAtom = atom<number>({
key: 'recommendIndexAtom',
default: 0,
});
1 change: 1 addition & 0 deletions src/types/SpaceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface GetGroupBestRegionProps {
latitude: number;
longitude: number;
moveUserInfo: GetUserInfoProps[];
index: number;
}

export interface GetUserInfoProps {
Expand Down

0 comments on commit 12b52d8

Please sign in to comment.