diff --git a/src/App.tsx b/src/App.tsx index 42f76ce..ad3f62e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,6 +18,7 @@ import CharacterEditPage from './pages/CharacterEditPage' import GuidePage from './pages/Guide' import FriendListPage from './pages/FriendListPage' import FriendRequestsPage from './pages/FriendRequestsPage' +import FriendCharacterDashboard from './pages/FriendCharacterDashboard' const darkTheme = createTheme({ palette: { @@ -49,6 +50,7 @@ function App() { } /> } /> } /> + } /> } /> diff --git a/src/pages/FriendCharacterDashboard.tsx b/src/pages/FriendCharacterDashboard.tsx new file mode 100644 index 0000000..5ea22ec --- /dev/null +++ b/src/pages/FriendCharacterDashboard.tsx @@ -0,0 +1,102 @@ +import { + Box, + Typography, + Card, + CardContent, + Grid, + Stack, + Checkbox, + Button +} from '@mui/material' +import { useEffect, useState } from 'react' +import { useNavigate, useParams } from 'react-router-dom' +import api from '../lib/api' + +interface Character { + character_id: number + character_name: string + server: string +} + +interface Homework { + homework_id: number + title: string + reset_type: string + clear_count: number + complete_cnt: number +} + +export default function FriendCharacterDashboard() { + const { friendId } = useParams() + const [characters, setCharacters] = useState([]) + const [homeworks, setHomeworks] = useState>({}) + const navigate = useNavigate() + + useEffect(() => { + const fetchData = async () => { + try { + const res = await api.get(`/friends/${friendId}/characters`) + setCharacters(res.data) + + const hwResults = await Promise.all( + res.data.map((char: Character) => + api + .get(`/friends/${friendId}/characters/${char.character_id}/homeworks`) + .then(r => ({ id: char.character_id, data: r.data })) + ) + ) + const map: Record = {} + hwResults.forEach(item => { + map[item.id] = item.data + }) + setHomeworks(map) + } catch (err) { + console.error('친구 대시보드 데이터를 불러오는 데 실패했습니다.', err) + } + } + fetchData() + }, [friendId]) + + return ( + + + + 친구 캐릭터 보기 + + + {characters.map(char => ( + + + + + {char.server} : {char.character_name} + + + {(homeworks[char.character_id] || []).map(hw => ( + + + {hw.title} ({hw.clear_count}회) + + + {Array.from({ length: hw.clear_count }).map((_, idx) => ( + + ))} + + + ))} + + + + + ))} + + + ) +}