diff --git a/apps/spectator/src/app/(home)/_components/tab.tsx b/apps/spectator/src/app/(home)/_components/tab.tsx index a2790ec3..1b0ab6c6 100644 --- a/apps/spectator/src/app/(home)/_components/tab.tsx +++ b/apps/spectator/src/app/(home)/_components/tab.tsx @@ -21,12 +21,21 @@ export const RecentTab = () => { if (!displayedGame) return null; - const hasPlayingGames = displayedGame.games.some((game) => game.gameState === 'PLAYING'); + const { games, leagueId, leagueName } = displayedGame; + + const hasPlayingGames = !games.every(({ gameState }) => gameState === 'FINISHED'); const buttonLabel = hasPlayingGames ? '응원하러 가기' : '지난 경기 보러가기'; - const sortedGames = [...displayedGame.games].sort( - (a, b) => new Date(b.startTime).getTime() - new Date(a.startTime).getTime(), - ); + // gameState가 PLAYING인 경기, SCHEDULED인 경기, FINISHED인 경기 순으로 정렬 + // 각 경기 상태 내에서는 시작 시간이 느린 순으로 정렬 + const sortedGames = [...games].sort((a, b) => { + const gameStateOrder = { PLAYING: 0, SCHEDULED: 1, FINISHED: 2 }; + const aOrder = gameStateOrder[a.gameState]; + const bOrder = gameStateOrder[b.gameState]; + + if (aOrder !== bOrder) return aOrder - bOrder; + return new Date(b.startTime).getTime() - new Date(a.startTime).getTime(); + }); const { data: cheerCount } = useSuspenseLeagueCheerCount( { leagueId: displayedGame?.leagueId }, @@ -37,8 +46,8 @@ export const RecentTab = () => {