Skip to content

Commit 308d8de

Browse files
committed
feat: 메인페이지 크루 api 부착
1 parent c32a04d commit 308d8de

6 files changed

Lines changed: 132 additions & 8 deletions

File tree

src/api/crews/getNearCrewList.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ export const getNearCrewList = async (params: GetNearCrewListRequest) => {
1010
params: params,
1111
});
1212

13+
console.log(params);
14+
1315
return data;
1416
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { CrewProfile } from '@type/models';
2+
3+
export const crewList: CrewProfile[] = Array(100)
4+
.fill({
5+
id: 1,
6+
name: '노드크루',
7+
content: '안녕하세요, 노드크루입니다. 백둥체육관 201호에서 진행합니다.',
8+
memberCount: 10,
9+
maxMemberCount: 15,
10+
profileImageUrl: 'pickpleCrewProfileImage.s3.ap-northeast-2.amazonaws.com',
11+
backgroundImageUrl:
12+
'pickpleCrewBackgroundImage.s3.ap-northeast-2.amazonaws.com',
13+
status: '모집 중',
14+
likeCount: 9,
15+
competitionPoint: 104,
16+
leader: {
17+
id: 1,
18+
email: 'james123@pickple.kr',
19+
nickname: 'james123',
20+
introduction: '안녕하십니까. 제임스입니다. 아이고~ 사장님~~',
21+
profileImageUrl: 'https://s3.amazonaws.com/pickple/james123.jpg',
22+
mannerScore: 21,
23+
mannerScoreCount: 30,
24+
addressDepth1: '서울시',
25+
addressDepth2: '강남구',
26+
positions: ['C', 'PF'],
27+
},
28+
addressDepth1: '서울시',
29+
addressDepth2: '강남구',
30+
members: [
31+
{
32+
id: 1,
33+
email: 'james123@pickple.kr',
34+
nickname: 'james123',
35+
introduction: '안녕하십니까. 제임스입니다. 아이고~ 사장님~~',
36+
profileImageUrl: 'https://s3.amazonaws.com/pickple/james123.jpg',
37+
mannerScore: 21,
38+
mannerScoreCount: 30,
39+
addressDepth1: '서울시',
40+
addressDepth2: '강남구',
41+
positions: ['C', 'PF'],
42+
},
43+
{
44+
id: 2,
45+
email: 'james456@pickple.kr',
46+
nickname: 'james456',
47+
introduction: '안녕하십니까. 제임스456입니다. 아이고~ 사장님~~',
48+
profileImageUrl: 'https://s3.amazonaws.com/pickple/james456.jpg',
49+
mannerScore: 26,
50+
mannerScoreCount: 30,
51+
addressDepth1: '서울시',
52+
addressDepth2: '강남구',
53+
positions: ['C'],
54+
},
55+
],
56+
})
57+
.map((crewList: CrewProfile, index) => ({
58+
...crewList,
59+
id: index + 1,
60+
}));
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { HttpResponse, http } from 'msw';
2+
3+
import { crewList } from '@mocks/data/crew/nearCrewList';
4+
5+
export const mockGetNearCrewList = http.get('/api/crews', ({ request }) => {
6+
const { searchParams } = new URL(request.url);
7+
const addressDepth1Value = searchParams.get('addressDepth1');
8+
const addressDepth2Value = searchParams.get('addressDepth2');
9+
const page = Number(searchParams.get('page'));
10+
const size = Number(searchParams.get('size'));
11+
12+
const startIndex = page * size;
13+
14+
return HttpResponse.json(
15+
crewList
16+
.filter(({ addressDepth1, addressDepth2 }) => {
17+
if (
18+
addressDepth1 === addressDepth1Value &&
19+
addressDepth2 === addressDepth2Value
20+
)
21+
return true;
22+
})
23+
.slice(startIndex, startIndex + size)
24+
);
25+
});

src/pages/AllServicesPage/AllServicesPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const AllServicesPage = () => {
3232
};
3333

3434
const getMyId = (): string | null => {
35-
const data = localStorage.getItem('USER_INFO');
35+
const data = localStorage.getItem('LOGIN_INFO');
3636

3737
if (!data) {
3838
return null;

src/pages/MainPage/MainPage.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useNavigate } from 'react-router-dom';
22

33
import { Authenticated, Registration } from '@/type/models';
44

5+
import { CrewItem } from '@components/CrewItem';
56
import { Header } from '@components/Header';
67
import { MatchItem } from '@components/MatchItem';
78
import { Button } from '@components/shared/Button';
@@ -12,6 +13,7 @@ import { theme } from '@styles/theme';
1213
import { PATH_NAME } from '@consts/pathName';
1314

1415
import { MainPageContainer, MainPageSubContainer } from './MainPage.style';
16+
import { useMainPageNearCrewListQuery } from './useMainPageNearCrewListQuery';
1517
import { useMainPageNearGamesQuery } from './useMainPageNearGamesQuery';
1618

1719
export const MainPage = () => {
@@ -36,14 +38,18 @@ export const MainPage = () => {
3638
};
3739

3840
const { addressDepth1, addressDepth2 } = loginInfo;
39-
const { data } = useMainPageNearGamesQuery({
41+
const { data: gameData } = useMainPageNearGamesQuery({
4042
category: 'location',
4143
value:
4244
addressDepth1 === null ? '서울시+강남구' : addressDepth2 + addressDepth2,
4345
});
44-
console.log(data);
4546

46-
const filteredData = data.map(
47+
const { data: crewData } = useMainPageNearCrewListQuery({
48+
addressDepth1: addressDepth1 === null ? '서울시' : addressDepth1,
49+
addressDepth2: addressDepth2 === null ? '영등포구' : addressDepth2,
50+
});
51+
52+
const filteredGameData = gameData.map(
4753
({
4854
id,
4955
//playStartTime,
@@ -68,12 +74,40 @@ export const MainPage = () => {
6874
)
6975
);
7076

77+
console.log(crewData);
78+
79+
const filteredCrewData = crewData.map(
80+
({
81+
id,
82+
name,
83+
addressDepth1,
84+
addressDepth2,
85+
profileImageUrl,
86+
members,
87+
memberCount,
88+
maxMemberCount,
89+
}) => (
90+
<CrewItem
91+
key={id.toString()}
92+
name={name}
93+
address={`${addressDepth1} ${addressDepth2}`}
94+
imgSrc={profileImageUrl}
95+
membersProfileImageUrls={members.map(
96+
({ profileImageUrl }) => profileImageUrl
97+
)}
98+
memberCount={memberCount}
99+
maxMemberCount={maxMemberCount}
100+
onClick={() => navigate(PATH_NAME.GET_CREWS_PATH(id.toString()))}
101+
/>
102+
)
103+
);
104+
71105
return (
72106
<MainPageContainer>
73107
<Header isLogo={true} />
74108
<MainPageSubContainer>
75109
<Text children={'내 근처의 경기'} weight={700} size={'1.25rem'} />
76-
{filteredData}
110+
{filteredGameData}
77111
<Button
78112
{...MAIN_PAGE_BUTTON_PROP}
79113
onClick={() => navigate(PATH_NAME.GAMES_NEAR)}
@@ -83,8 +117,11 @@ export const MainPage = () => {
83117
</MainPageSubContainer>
84118
<MainPageSubContainer>
85119
<Text children={'추천 크루'} weight={700} size={'1.25rem'} />
86-
{filteredData}
87-
<Button {...MAIN_PAGE_BUTTON_PROP} onClick={() => console.log('hi')}>
120+
{filteredCrewData}
121+
<Button
122+
{...MAIN_PAGE_BUTTON_PROP}
123+
onClick={() => navigate(PATH_NAME.CREWS_RECOMMEND)}
124+
>
88125
더보기
89126
</Button>
90127
</MainPageSubContainer>

src/pages/MainPage/useMainPageNearCrewListQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const useMainPageNearCrewListQuery = ({
1717
getNearCrewList({
1818
addressDepth1,
1919
addressDepth2,
20-
page: 1,
20+
page: 0,
2121
size: FETCH_SIZE,
2222
}),
2323
});

0 commit comments

Comments
 (0)