fix: stabilize competition results flow

This commit is contained in:
dahyeon committed 2026-07-13 13:55:08 +00:00
1 parent 3bd3120eb1
commit a88562b208
20 files changed
+411 -65

No files matched your search

+86 -5
View File
@@ -1,18 +1,27 @@
import type { CompetitionDetailResponse } from "@lolympus/contracts";
import { useEffect, useRef, useState } from "react";
import { Link, useParams } from "react-router";
import { Link, useParams, useSearchParams } from "react-router";
import { useCompetition, useTeamCompetition } from "../api/hooks";
import { SeriesScoreCard } from "../components/competition/SeriesScoreCard";
import { DEFAULT_COMMUNITY_ID } from "../config";
import {
getTeamProgressErrorContent,
isConsistentTeamProgressSnapshot,
shouldOfferTeamSelection,
type TeamProgressErrorContent,
} from "./match-team-progress-state";
export default function MatchTeamProgressPage() {
const { id } = useParams();
const [searchParams] = useSearchParams();
const selectedTeamId = searchParams.get("teamId") ?? undefined;
const isSelectingTeam = !selectedTeamId && searchParams.get("select") === "1";
const competitionQuery = useCompetition(id, DEFAULT_COMMUNITY_ID);
const teamQuery = useTeamCompetition(id, DEFAULT_COMMUNITY_ID);
const teamQuery = useTeamCompetition(
id,
DEFAULT_COMMUNITY_ID,
selectedTeamId,
);
const refetchCompetition = competitionQuery.refetch;
const refetchTeam = teamQuery.refetch;
const [copiedSlotId, setCopiedSlotId] = useState<string | null>(null);
@@ -63,11 +72,24 @@ export default function MatchTeamProgressPage() {
);
}
if (isSelectingTeam && competition) {
return <TeamSelectionState competition={competition} matchId={id} />;
}
if (competitionQuery.isLoading || teamQuery.isLoading) {
return <TeamProgressLoadingState />;
}
if (hasQueryError) {
// The caller could not be resolved to a team from their identity — let them
// name the team instead, so the page stays usable without signing in.
if (
competition &&
!competitionQuery.error &&
shouldOfferTeamSelection([teamQuery.error], selectedTeamId)
) {
return <TeamSelectionState competition={competition} matchId={id} />;
}
return (
<TeamProgressProblemState
content={getTeamProgressErrorContent(
@@ -142,12 +164,20 @@ export default function MatchTeamProgressPage() {
<header className="mb-6 border-b border-base-content/10 pb-5">
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
My Competition
{selectedTeamId ? "Team Competition" : "My Competition"}
</p>
<h1 className="mt-1 text-2xl font-black">{team?.name ?? "내 팀"}</h1>
<h1 className="mt-1 text-2xl font-black">
{team?.name ?? (selectedTeamId ? "팀" : "내 팀")}
</h1>
<p className="mt-1 text-sm text-base-content/45">
우리 팀의 공식 대진과 토너먼트 코드는 이 페이지에서만 표시됩니다.
해당 팀의 공식 대진과 토너먼트 코드가 표시됩니다.
</p>
<Link
to={`/match/${id}/team?select=1`}
className="mt-2 inline-flex text-xs text-base-content/40 hover:text-primary"
>
다른 팀 보기
</Link>
</header>
<section className="mb-6" aria-labelledby="active-series-heading">
@@ -279,6 +309,57 @@ export default function MatchTeamProgressPage() {
);
}
function TeamSelectionState({
competition,
matchId,
}: {
competition: CompetitionDetailResponse;
matchId: string | undefined;
}) {
return (
<main className="mx-auto max-w-5xl px-4 py-6 sm:px-6">
<Link
to={`/match/${matchId}`}
className="mb-5 inline-flex text-xs text-base-content/40 hover:text-base-content"
>
← 내전 상세로
</Link>
<header className="mb-6 border-b border-base-content/10 pb-5">
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
Team Competition
</p>
<h1 className="mt-1 text-2xl font-black">팀 선택</h1>
<p className="mt-1 text-sm text-base-content/45">
진행 상황과 토너먼트 코드를 확인할 팀을 선택해 주세요.
</p>
</header>
{competition.teams.length > 0 ? (
<ul className="grid gap-3 sm:grid-cols-2">
{competition.teams.map((team) => (
<li key={team.teamId}>
<Link
to={`/match/${matchId}/team?teamId=${team.teamId}`}
className="flex items-center justify-between gap-3 border border-base-content/10 bg-base-100 px-4 py-4 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
>
<span className="min-w-0 truncate text-sm font-bold">
{team.name}
</span>
<span className="shrink-0 text-xs text-base-content/35">
{team.members.length}명
</span>
</Link>
</li>
))}
</ul>
) : (
<EmptyState message="구성된 팀이 없습니다." />
)}
</main>
);
}
function TeamProgressLoadingState() {
return (
<main