fix: stabilize competition results flow
This commit is contained in:
1 parent
3bd3120eb1
commit
a88562b208
20 files changed
+411
-65
No files matched your search
@@ -257,12 +257,15 @@ export function useCompetition(
|
||||
export function useTeamCompetition(
|
||||
matchId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
teamId?: string,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['competition-team', communityId, matchId ?? null],
|
||||
queryKey: ['competition-team', communityId, matchId ?? null, teamId ?? null],
|
||||
queryFn: () =>
|
||||
apiFetch<TeamCompetitionViewResponse>(
|
||||
`/communities/${communityId}/matches/${matchId}/competition/team`,
|
||||
`/communities/${communityId}/matches/${matchId}/competition/team${
|
||||
teamId ? `?teamId=${encodeURIComponent(teamId)}` : ''
|
||||
}`,
|
||||
),
|
||||
enabled: Boolean(communityId && matchId),
|
||||
retry: false,
|
||||
|
||||
@@ -45,7 +45,7 @@ export function CompetitionResults({
|
||||
to={`/match/${competition.matchId}/team`}
|
||||
className="border border-base-content/10 px-2.5 py-1.5 text-xs font-bold text-base-content/55 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
내 팀 진행
|
||||
팀 진행
|
||||
</Link>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
DoubleEliminationBracketLayout,
|
||||
} from "./double-elimination-bracket-layout";
|
||||
import { DOUBLE_ELIMINATION_BRACKET_GEOMETRY } from "./double-elimination-bracket-layout";
|
||||
import { DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS } from "./competition-display-layout";
|
||||
import { DoubleEliminationMobileBracket } from "./DoubleEliminationMobileBracket";
|
||||
import { SeriesScoreCard } from "./SeriesScoreCard";
|
||||
|
||||
@@ -57,7 +58,9 @@ function DesktopBracket({
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="hidden xl:block">
|
||||
<div
|
||||
className={`hidden xl:block ${DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS}`}
|
||||
>
|
||||
<div className="mb-2 flex flex-wrap items-center justify-between gap-3 text-xs text-content-muted">
|
||||
<p>
|
||||
승자조와 패자조는 같은 시간축을 공유하며 오른쪽 결승에서 합류합니다.
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import type {
|
||||
CompetitionDetailResponse,
|
||||
MatchGameMode,
|
||||
} from "@lolympus/contracts";
|
||||
import type { CompetitionDetailResponse } from "@lolympus/contracts";
|
||||
import { createDoubleEliminationBracketLayout } from "./double-elimination-bracket-layout.ts";
|
||||
|
||||
export function matchPageMaxWidthClass(gameMode: MatchGameMode): string {
|
||||
return gameMode === "double-elimination" ? "max-w-[1600px]" : "max-w-5xl";
|
||||
}
|
||||
export const MATCH_PAGE_MAX_WIDTH_CLASS = "max-w-5xl";
|
||||
|
||||
export const DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS =
|
||||
"relative left-1/2 w-[calc(100vw-3rem)] max-w-[1600px] -translate-x-1/2";
|
||||
|
||||
export function createCompetitionBracketLayout(
|
||||
competition: CompetitionDetailResponse,
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
import { RankBadge } from "../components/RankBadge";
|
||||
import { CompetitionAdminControls } from "../components/competition/CompetitionAdminControls";
|
||||
import { CompetitionResults } from "../components/competition/CompetitionResults";
|
||||
import { matchPageMaxWidthClass } from "../components/competition/competition-display-layout";
|
||||
import { MATCH_PAGE_MAX_WIDTH_CLASS } from "../components/competition/competition-display-layout";
|
||||
import { DEFAULT_COMMUNITY_ID, useAuthUserId } from "../config";
|
||||
import { apiFetch, ApiError } from "../lib/api";
|
||||
import { profileIconUrl } from "../lib/ddragon";
|
||||
@@ -1795,7 +1795,7 @@ export default function MatchDetailPage() {
|
||||
return (
|
||||
<main
|
||||
className={`mx-auto px-4 py-6 sm:px-6 ${
|
||||
matchPageMaxWidthClass(matchQuery.data.gameMode)
|
||||
MATCH_PAGE_MAX_WIDTH_CLASS
|
||||
}`}
|
||||
>
|
||||
<Link
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -26,15 +26,24 @@ export function isConsistentTeamProgressSnapshot(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A visitor who is not signed in (401) — or is signed in but belongs to no team
|
||||
* in this Competition (403) — can still read a team view by naming the team.
|
||||
* Offer the team picker instead of an error until they have named one.
|
||||
*/
|
||||
export function shouldOfferTeamSelection(
|
||||
errors: readonly unknown[],
|
||||
selectedTeamId: string | undefined,
|
||||
): boolean {
|
||||
if (selectedTeamId) return false;
|
||||
const statuses = errorStatuses(errors);
|
||||
return statuses.includes(401) || statuses.includes(403);
|
||||
}
|
||||
|
||||
export function getTeamProgressErrorContent(
|
||||
errors: readonly unknown[],
|
||||
): TeamProgressErrorContent {
|
||||
const statuses = errors.flatMap((error) => {
|
||||
if (typeof error !== "object" || error === null || !("status" in error)) {
|
||||
return [];
|
||||
}
|
||||
return typeof error.status === "number" ? [error.status] : [];
|
||||
});
|
||||
const statuses = errorStatuses(errors);
|
||||
|
||||
if (statuses.includes(401)) {
|
||||
return {
|
||||
@@ -86,6 +95,15 @@ export function getTeamProgressErrorContent(
|
||||
};
|
||||
}
|
||||
|
||||
function errorStatuses(errors: readonly unknown[]): number[] {
|
||||
return errors.flatMap((error) => {
|
||||
if (typeof error !== "object" || error === null || !("status" in error)) {
|
||||
return [];
|
||||
}
|
||||
return typeof error.status === "number" ? [error.status] : [];
|
||||
});
|
||||
}
|
||||
|
||||
function isNetworkError(error: unknown): boolean {
|
||||
return (
|
||||
error instanceof TypeError ||
|
||||
|
||||
Reference in new issue
Block a user