-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ feat ] 뱃지 api 연결
- Loading branch information
Showing
7 changed files
with
82 additions
and
68 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { get } from './core'; | ||
|
||
export interface badgeDate { | ||
regDtm: string; | ||
} | ||
export interface badge { | ||
badgeId: string; | ||
badgeName: string; | ||
badgeCnt: number; | ||
imageUrl: string; | ||
explanation: string; | ||
qualification: string; | ||
gainDate: badgeDate[]; | ||
gainYn: 'Y' | 'N'; | ||
} | ||
export const getBadges = async (): Promise<badge[]> => { | ||
return await get('/badge/list'); | ||
}; |
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 |
---|---|---|
@@ -1,29 +1,40 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import BadgeList from './components/BadgeList'; | ||
import exampleImg from '@/assets/img/badge_example.png'; | ||
import { getBadges, badge } from '@/api/badge'; | ||
|
||
export default function BadgePage() { | ||
const navigate = useNavigate(); | ||
const [badges, setBadges] = useState<badge[]>([]); | ||
|
||
const fakeBadgeList = Array.from({ length: 20 }).map((_, idx) => ({ | ||
name: '완벽한 출발', | ||
imgSrc: exampleImg, | ||
key: idx, | ||
locked: idx % 2 ? true : false, | ||
count: 3, | ||
})); | ||
useEffect(() => { | ||
getBadgeList(); | ||
}, []); | ||
|
||
const routeToBadgeDetail = (key: number) => { | ||
const badge = fakeBadgeList.find((badge) => badge.key === key); | ||
const getBadgeList = async () => { | ||
const result = await getBadges(); | ||
setBadges(result); | ||
}; | ||
|
||
const routeToBadgeDetail = (id: string, badgeList: badge[]) => { | ||
const badge = badgeList.find((badge) => badge.badgeId === id); | ||
|
||
if (!badge?.locked) { | ||
navigate(`/badge/${key}`); | ||
if (badge && badge.badgeCnt > 0) { | ||
navigate(`/badge/${badge.badgeId}`, { | ||
state: { | ||
name: badge.badgeName, | ||
count: badge.badgeCnt, | ||
dates: badge.gainDate, | ||
explanation: badge.explanation, | ||
imgUrl: import.meta.env.VITE_STORAGE_URL + badge.badgeId + '.png', | ||
}, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<BadgeList badgeList={fakeBadgeList} clickHandler={routeToBadgeDetail} /> | ||
<BadgeList badgeList={badges} clickHandler={routeToBadgeDetail} /> | ||
</div> | ||
); | ||
} |
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