-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 라운드 통계 화면 및 게임 결과 화면 구현 #73
Changes from 26 commits
e61ea09
0128c04
752c497
9650f21
91f40b3
c65abe3
aa3b05a
a200136
be3f49a
7103261
2d26903
a04c200
d8a6d53
f46054d
090e2e4
27715e0
73c9f90
93dd3c3
76a259c
6e4ec20
0a65739
261aa4e
347cfb5
adbed42
dfc98e4
7a2deb5
8defa35
04ffc25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { fetchFinalGameResult } from '@/apis/balanceContent'; | ||
|
||
const useGameResultQuery = () => { | ||
const gameResultQuery = useQuery({ | ||
queryKey: ['gameResult'], | ||
queryFn: async () => await fetchFinalGameResult(), | ||
}); | ||
|
||
return { ...gameResultQuery, gameResult: gameResultQuery.data }; | ||
}; | ||
|
||
export { useGameResultQuery }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
import { Theme } from '@/styles/Theme'; | ||
|
||
export const gameResultLayout = css` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 40vh; | ||
gap: 6rem; | ||
gap: 4.8rem; | ||
width: 100%; | ||
`; | ||
|
||
export const gameResultTitleWrapper = css` | ||
display: flex; | ||
flex-basis: 20%; | ||
export const gameResultTitle = css` | ||
${Theme.typography.slogan}; | ||
`; | ||
|
||
export const gameResultTitle = css` | ||
font-weight: bold; | ||
font-size: 2.4rem; | ||
export const rankListContainer = css` | ||
display: flex; | ||
flex-basis: 60%; | ||
flex-direction: column; | ||
gap: 2rem; | ||
width: 100%; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { gameResultTitle, gameResultTitleWrapper, gameResultLayout } from './GameResult.styled'; | ||
|
||
import Button from '@/components/common/Button/Button'; | ||
import { useGameResultQuery } from './GameResult.hook'; | ||
import { gameResultTitle, gameResultLayout, rankListContainer } from './GameResult.styled'; | ||
import FinalButton from '../common/FinalButton/FinalButton'; | ||
import GameResultItem from '../GameResultItem/GameResultItem'; | ||
|
||
const GameResult = () => { | ||
const navigate = useNavigate(); | ||
|
||
const goToHome = () => { | ||
navigate('/'); | ||
}; | ||
const { gameResult } = useGameResultQuery(); | ||
|
||
return ( | ||
<div css={gameResultLayout}> | ||
<div css={gameResultTitleWrapper}> | ||
<> | ||
<div css={gameResultLayout}> | ||
<h1 css={gameResultTitle}>게임 결과</h1> | ||
<div css={rankListContainer}> | ||
{gameResult && | ||
gameResult.map((item) => <GameResultItem key={item.rank} gameFinalResult={item} />)} | ||
</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L4 - 변경 제안게임 결과에서 매칭도가 순위대로 나열되는 것을 리스트로 볼 수 있을 것 같아서, div 대신에 ol 태그로 수정하는 것은 어떻게 생각하시나요? 😊 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 좋습니다아 웹표준 고려하여 태그 사용하는 것 너무 좋네요 ㅎㅎ |
||
</div> | ||
<Button text="확인" onClick={goToHome} /> | ||
</div> | ||
<FinalButton /> | ||
</> | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
import { Theme } from '@/styles/Theme'; | ||
|
||
export const rankItem = css` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
${Theme.typography.headline3}; | ||
`; | ||
|
||
export const rankInfoContainer = css` | ||
display: flex; | ||
flex-basis: 85%; | ||
align-items: center; | ||
gap: 1.2rem; | ||
`; | ||
|
||
export const rankNumber = css` | ||
${Theme.typography.headline1} | ||
`; | ||
|
||
export const nicknameContainer = (percent: number) => css` | ||
display: flex; | ||
overflow: visible; | ||
gap: 1rem; | ||
width: ${percent > 5 ? percent - 5 : percent}%; | ||
height: 100%; | ||
padding: 1.2rem; | ||
border-radius: ${Theme.borderRadius.radius20}; | ||
|
||
background-color: ${Theme.color.peanut400}; | ||
transition: all 2s; | ||
`; | ||
|
||
export const rankPercent = css` | ||
${Theme.typography.headline3} | ||
`; | ||
|
||
export const nickname = css` | ||
min-width: 5.6rem; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
nickname, | ||
nicknameContainer, | ||
rankInfoContainer, | ||
rankItem, | ||
rankNumber, | ||
rankPercent, | ||
} from './GameResultItem.styled'; | ||
|
||
import useCountAnimation from '@/hooks/useCountAnimation'; | ||
import { GameFinalResult } from '@/types/balanceContent'; | ||
|
||
interface GameResultItemProps { | ||
gameFinalResult: GameFinalResult; | ||
} | ||
const GameResultItem = ({ gameFinalResult }: GameResultItemProps) => { | ||
const animatedRankPercent = useCountAnimation({ | ||
target: gameFinalResult.percent, | ||
duration: 3000, | ||
}); | ||
|
||
return ( | ||
<div css={rankItem}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L4 - 변경 제안상위 태그가 ol로 변경된다면 여기는 li 태그로 리스트임을 알려줄 수 있을 것 같아요 ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니당 |
||
<div css={rankInfoContainer}> | ||
<span css={rankNumber}>{gameFinalResult.rank}</span> | ||
<div css={nicknameContainer(animatedRankPercent)}> | ||
<span>🥜</span> | ||
<span css={nickname}>{gameFinalResult.name}</span> | ||
</div> | ||
</div> | ||
<span css={rankPercent}>{animatedRankPercent}%</span> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GameResultItem; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import useCountAnimation from '@/hooks/useCountAnimation'; | ||
import { Total, Group } from '@/types/roundVoteResult'; | ||
|
||
export const useTotalCountAnimation = (groupRoundResult?: Group, totalResult?: Total) => { | ||
const animatedFirstPercent = useCountAnimation({ target: groupRoundResult?.firstOption.percent }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L4 - 변경 제안groupRoundResult가 undefined 일 수도 있으니까 그것에 대한 처리도 있으면 좋을 것 같아요! 제가 지금 생각난 방법은 아예 없는 경우 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useRoundVoteResultQuery 에 |
||
const animatedSecondPercent = useCountAnimation({ | ||
target: groupRoundResult?.secondOption.percent, | ||
}); | ||
|
||
const animatedTotalFirstPercent = useCountAnimation({ target: totalResult?.firstOption.percent }); | ||
const animatedTotalSecondPercent = useCountAnimation({ | ||
target: totalResult?.secondOption.percent, | ||
}); | ||
|
||
return { | ||
animatedFirstPercent, | ||
animatedSecondPercent, | ||
animatedTotalFirstPercent, | ||
animatedTotalSecondPercent, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
export const tabLayout = css` | ||
display: flex; | ||
flex-basis: 45%; | ||
flex-direction: column; | ||
width: 100%; | ||
|
||
transition: all 1s; | ||
`; | ||
|
||
export const tabWrapperStyle = css` | ||
display: flex; | ||
width: 40%; | ||
margin-left: 2.4rem; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useState } from 'react'; | ||
|
||
import { useTotalCountAnimation } from './RoundResultTab.hook'; | ||
import { tabLayout, tabWrapperStyle } from './RoundResultTab.styled'; | ||
import TabContentContainer from '../TabContentContainer/TabContentContainer'; | ||
import TabItem from '../TabItem/TabItem'; | ||
|
||
import useRoundVoteResultQuery from '@/hooks/useRoundVoteResultQuery'; | ||
|
||
const RoundResultTab = () => { | ||
const [activeTab, setActiveTab] = useState<'group' | 'total'>('group'); | ||
const isGroupTabActive = activeTab === 'group'; | ||
|
||
const { groupRoundResult, totalResult } = useRoundVoteResultQuery(); | ||
const { | ||
animatedFirstPercent, | ||
animatedSecondPercent, | ||
animatedTotalFirstPercent, | ||
animatedTotalSecondPercent, | ||
} = useTotalCountAnimation(groupRoundResult, totalResult); | ||
|
||
const handleClickTab = (clickedTab: 'group' | 'total') => { | ||
setActiveTab(clickedTab); | ||
}; | ||
|
||
if (!groupRoundResult || !totalResult) return <div>데이터가 없습니다</div>; | ||
|
||
return ( | ||
<div css={tabLayout}> | ||
<div css={tabWrapperStyle}> | ||
<TabItem tab="group" activeTab={activeTab} handleClickTab={handleClickTab} /> | ||
<TabItem tab="total" activeTab={activeTab} handleClickTab={handleClickTab} /> | ||
</div> | ||
<TabContentContainer | ||
isGroupTabActive={isGroupTabActive} | ||
roundResult={isGroupTabActive ? groupRoundResult : totalResult} | ||
animatedFirstPercent={isGroupTabActive ? animatedFirstPercent : animatedTotalFirstPercent} | ||
animatedSecondPercent={ | ||
isGroupTabActive ? animatedSecondPercent : animatedTotalSecondPercent | ||
} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RoundResultTab; |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L5 - 참고 의견
no console 이거 흔히 하는 실수인데 방지하는 옵션 좋네요 굿