|
| 1 | +import { useNavigate } from 'react-router-dom'; |
| 2 | + |
| 3 | +import { CrewItem } from '@components/CrewItem'; |
| 4 | +import { Header } from '@components/Header'; |
| 5 | +import { Text } from '@components/shared/Text'; |
| 6 | + |
| 7 | +import { useNearCrewListQuery } from '@hooks/queries/useNearCrewListQuery'; |
| 8 | +import { useHeaderTitle } from '@hooks/useHeaderTitle'; |
| 9 | +import { useInfiniteScroll } from '@hooks/useInfiniteScroll'; |
| 10 | + |
| 11 | +import { useLoginInfoStore } from '@stores/loginInfo.store'; |
| 12 | + |
| 13 | +import { PATH_NAME } from '@consts/pathName'; |
| 14 | + |
| 15 | +import { PageContent, PageWrapper } from './CrewsRecommendPage.styles'; |
| 16 | + |
| 17 | +const DEFAULT_ADDRESS_DEPTHS = { |
| 18 | + addressDepth1: '서울시', |
| 19 | + addressDepth2: '강남구', |
| 20 | +} as const; |
| 21 | + |
| 22 | +export const CrewsRecommendPage = () => { |
| 23 | + const loginInfo = useLoginInfoStore((state) => state.loginInfo); |
| 24 | + |
| 25 | + const { nearCrews, fetchNextPage } = useNearCrewListQuery( |
| 26 | + loginInfo && loginInfo.addressDepth1 !== null |
| 27 | + ? { |
| 28 | + addressDepth1: loginInfo.addressDepth1, |
| 29 | + addressDepth2: loginInfo.addressDepth2, |
| 30 | + } |
| 31 | + : DEFAULT_ADDRESS_DEPTHS |
| 32 | + ); |
| 33 | + |
| 34 | + const { entryRef, showHeaderTitle } = useHeaderTitle<HTMLDivElement>(); |
| 35 | + const lastElementRef = useInfiniteScroll<HTMLDivElement>(fetchNextPage); |
| 36 | + const navigate = useNavigate(); |
| 37 | + |
| 38 | + return ( |
| 39 | + <PageWrapper> |
| 40 | + <Header title={showHeaderTitle ? '추천 크루' : ''} /> |
| 41 | + <PageContent> |
| 42 | + <div ref={entryRef}> |
| 43 | + <Text size={20} weight={700}> |
| 44 | + 추천 크루 |
| 45 | + </Text> |
| 46 | + </div> |
| 47 | + {nearCrews.map((crew) => { |
| 48 | + const membersProfileImageUrls = crew.members.map( |
| 49 | + (member) => member.profileImageUrl |
| 50 | + ); |
| 51 | + return ( |
| 52 | + <CrewItem |
| 53 | + key={crew.id} |
| 54 | + name={crew.name} |
| 55 | + address={`${crew.addressDepth1} ${crew.addressDepth2}`} |
| 56 | + imgSrc={crew.profileImageUrl} |
| 57 | + membersProfileImageUrls={membersProfileImageUrls} |
| 58 | + memberCount={crew.memberCount} |
| 59 | + maxMemberCount={crew.maxMemberCount} |
| 60 | + onClick={() => |
| 61 | + navigate(PATH_NAME.GET_CREWS_PATH(String(crew.id))) |
| 62 | + } |
| 63 | + /> |
| 64 | + ); |
| 65 | + })} |
| 66 | + <div ref={lastElementRef}></div> |
| 67 | + </PageContent> |
| 68 | + </PageWrapper> |
| 69 | + ); |
| 70 | +}; |
0 commit comments