Skip to content

Commit abcd04c

Browse files
authored
Merge pull request #110 from geulDa/api/#107/main-api
Api: main 페이지 스탬프 조회 api 연결
2 parents 883d393 + 70af714 commit abcd04c

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

src/pages/main/index.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import { BottomNav, ControlBar } from '@/shared/components';
33
import Image from 'next/image';
44
import { useRouter } from 'next/router';
55
import StampBoard from '@/shared/components/main/components/stampBoard/StampBoard';
6+
import { useGetStampStatus } from '@/shared/main/queries/useGetStampStatus';
67

78
export default function MainPage() {
89
const router = useRouter();
10+
11+
const { data, isLoading, isError } = useGetStampStatus();
12+
913
return (
1014
<div
1115
className={cn(
1216
'px-[2.4rem] bg-white flex flex-col gap-[1rem] h-full pt-[1.3rem] pb-[12rem]',
1317
)}
14-
>
18+
>
1519
<ControlBar
1620
isLoggedIn={false}
1721
onLogin={() => {}}
@@ -23,18 +27,18 @@ export default function MainPage() {
2327
<section>
2428
<Image
2529
src='/assets/bannerMain.svg'
26-
alt=""
27-
aria-hidden="true"
30+
alt=''
31+
aria-hidden='true'
2832
width={354}
2933
height={79}
3034
className='w-full h-auto object-cover block'
3135
/>
3236
</section>
3337

3438
<section
35-
role="button"
39+
role='button'
3640
tabIndex={0}
37-
aria-label="보드판으로 이동"
41+
aria-label='보드판으로 이동'
3842
onClick={() => {
3943
router.push('/main/Board');
4044
}}
@@ -44,12 +48,24 @@ export default function MainPage() {
4448
alt='보드판'
4549
width={354}
4650
height={426.36}
47-
className='w-full h-auto object-cover block'
51+
className='w-full h-auto object-cover block cursor-pointer transition-transform hover:scale-[1.01]'
4852
/>
4953
</section>
5054

51-
<StampBoard count={3} total={10} />
55+
{isLoading ? (
56+
<p className='text-gray-400 text-center py-4'>불러오는 중...</p>
57+
) : isError ? (
58+
<p className='text-red-400 text-center py-4'>
59+
데이터를 불러오지 못했습니다 😢
60+
</p>
61+
) : (
62+
<StampBoard
63+
count={data?.collectedStampCount ?? 0}
64+
total={data?.totalStampCount ?? 10}
65+
/>
66+
)}
5267
</main>
68+
5369
<BottomNav />
5470
</div>
5571
);

src/shared/main/getStampStatus.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { apiAuth } from '@/shared/api/instance';
2+
import type { ApiResponse } from '@/shared/types/authtypes';
3+
4+
export interface StampStatus {
5+
totalStampCount: number;
6+
collectedStampCount: number;
7+
stampIds: number[];
8+
}
9+
10+
export const getStampStatus = async (): Promise<StampStatus> => {
11+
const { data } = await apiAuth.get<ApiResponse<StampStatus>>(
12+
'/api/stamps/collection',
13+
);
14+
return data.data;
15+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { getStampStatus } from '@/shared/main/getStampStatus';
3+
4+
/**
5+
* 스탬프 수집 현황 조회
6+
* - 비로그인도 가능
7+
*/
8+
9+
export const useGetStampStatus = () => {
10+
return useQuery({
11+
queryKey: ['stampStatus'],
12+
queryFn: getStampStatus,
13+
});
14+
};

0 commit comments

Comments
 (0)