Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions apps/spectator/src/app/(home)/_components/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -37,8 +46,8 @@ export const RecentTab = () => {
<div className="flex flex-1 flex-col gap-3">
<GameList
cheerCount={cheerCount.cheerTalkCount}
leagueId={displayedGame.leagueId}
leagueName={displayedGame.leagueName}
leagueId={leagueId}
leagueName={leagueName}
games={sortedGames}
buttonLabel={buttonLabel}
/>
Expand Down