fix: close competition cutover integrity gaps
This commit is contained in:
1 parent
7ea2002975
commit
683d602d63
57 files changed
+4805
-1582
No files matched your search
@@ -1,5 +1,9 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import type {
|
||||
MatchDetailResponse,
|
||||
MatchParticipantView,
|
||||
} from "@lolympus/contracts";
|
||||
import { ChevronLeft, Search, X } from "lucide-react";
|
||||
import { Link, useLocation, useNavigate, useParams } from "react-router";
|
||||
import {
|
||||
@@ -37,8 +41,6 @@ import type {
|
||||
AuctionTopTierThreshold,
|
||||
ApiCommunityUserSearchCandidate,
|
||||
ApiCommunityUserSearchRiotAccount,
|
||||
ApiMatch,
|
||||
ApiMatchParticipant,
|
||||
ApiPositionPreference,
|
||||
ApiTierInfo,
|
||||
ManualTournamentResultCollectResponse,
|
||||
@@ -138,7 +140,7 @@ function parseAuctionSecondsInput(value: string, min: number) {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
function buildAuctionParticipantPool(participants: ApiMatchParticipant[]) {
|
||||
function buildAuctionParticipantPool(participants: MatchParticipantView[]) {
|
||||
const ordered = [...participants].sort(
|
||||
(left, right) =>
|
||||
new Date(left.joinedAt).getTime() - new Date(right.joinedAt).getTime(),
|
||||
@@ -148,7 +150,7 @@ function buildAuctionParticipantPool(participants: ApiMatchParticipant[]) {
|
||||
}
|
||||
|
||||
function buildCaptainSlots(
|
||||
participants: ApiMatchParticipant[],
|
||||
participants: MatchParticipantView[],
|
||||
): CaptainSelectionSlot[] {
|
||||
const teamCount = Math.floor(
|
||||
buildAuctionParticipantPool(participants).length / 5,
|
||||
@@ -1451,7 +1453,7 @@ export default function MatchDetailPage() {
|
||||
},
|
||||
});
|
||||
|
||||
const matchQueryKey = ["match", DEFAULT_COMMUNITY_ID, id ?? null];
|
||||
const matchQueryKey = matchQuery.queryKey;
|
||||
|
||||
const addParticipantMutation = useMutation({
|
||||
mutationFn: ({
|
||||
@@ -1463,7 +1465,7 @@ export default function MatchDetailPage() {
|
||||
preferredPositions: ApiPositionPreference[];
|
||||
riotPuuid?: string;
|
||||
}) =>
|
||||
apiFetch<ApiMatch>(
|
||||
apiFetch<MatchDetailResponse>(
|
||||
`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/participants/${userId}`,
|
||||
{
|
||||
method: "POST",
|
||||
@@ -1488,9 +1490,10 @@ export default function MatchDetailPage() {
|
||||
),
|
||||
onMutate: async (userId: string) => {
|
||||
await queryClient.cancelQueries({ queryKey: matchQueryKey });
|
||||
const previous = queryClient.getQueryData<ApiMatch>(matchQueryKey);
|
||||
const previous =
|
||||
queryClient.getQueryData<MatchDetailResponse>(matchQueryKey);
|
||||
if (previous) {
|
||||
queryClient.setQueryData<ApiMatch>(matchQueryKey, {
|
||||
queryClient.setQueryData<MatchDetailResponse>(matchQueryKey, {
|
||||
...previous,
|
||||
participants: previous.participants.filter(
|
||||
(participant) => participant.userId !== userId,
|
||||
@@ -1531,9 +1534,10 @@ export default function MatchDetailPage() {
|
||||
),
|
||||
onMutate: async ({ userId, mainPosition, subPosition }) => {
|
||||
await queryClient.cancelQueries({ queryKey: matchQueryKey });
|
||||
const previous = queryClient.getQueryData<ApiMatch>(matchQueryKey);
|
||||
const previous =
|
||||
queryClient.getQueryData<MatchDetailResponse>(matchQueryKey);
|
||||
if (previous) {
|
||||
queryClient.setQueryData<ApiMatch>(matchQueryKey, {
|
||||
queryClient.setQueryData<MatchDetailResponse>(matchQueryKey, {
|
||||
...previous,
|
||||
participants: previous.participants.map((participant) =>
|
||||
participant.userId === userId
|
||||
@@ -1759,7 +1763,7 @@ export default function MatchDetailPage() {
|
||||
const manualPriorityCandidates = auctionParticipantPool.filter(
|
||||
(participant) => !selectedCaptainIds.includes(participant.userId),
|
||||
);
|
||||
const manualPriorityCandidateIds = new Set(
|
||||
const manualPriorityCandidateIds = new Set<string>(
|
||||
manualPriorityCandidates.map((participant) => participant.userId),
|
||||
);
|
||||
const selectedManualTopTierUserIds =
|
||||
|
||||
@@ -1,41 +1,112 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link, useParams } from "react-router";
|
||||
import { useCompetition, useTeamCompetition } from "../api/hooks";
|
||||
import { SeriesScoreCard } from "../components/competition/SeriesScoreCard";
|
||||
import { DEFAULT_COMMUNITY_ID } from "../config";
|
||||
import {
|
||||
getTeamProgressErrorContent,
|
||||
isConsistentTeamProgressSnapshot,
|
||||
type TeamProgressErrorContent,
|
||||
} from "./match-team-progress-state";
|
||||
|
||||
export default function MatchTeamProgressPage() {
|
||||
const { id } = useParams();
|
||||
const competitionQuery = useCompetition(id, DEFAULT_COMMUNITY_ID);
|
||||
const teamQuery = useTeamCompetition(id, DEFAULT_COMMUNITY_ID);
|
||||
const refetchCompetition = competitionQuery.refetch;
|
||||
const refetchTeam = teamQuery.refetch;
|
||||
const [copiedSlotId, setCopiedSlotId] = useState<string | null>(null);
|
||||
const lastAutoRefetchedMismatchRef = useRef<string | null>(null);
|
||||
const competition = competitionQuery.data;
|
||||
const teamView = teamQuery.data;
|
||||
const hasQueryError = Boolean(
|
||||
competitionQuery.error || teamQuery.error,
|
||||
);
|
||||
const isRefetching = competitionQuery.isFetching || teamQuery.isFetching;
|
||||
const revisionsMatch = isConsistentTeamProgressSnapshot(
|
||||
competition,
|
||||
teamView,
|
||||
);
|
||||
const revisionMismatchKey =
|
||||
competition && teamView && !revisionsMatch
|
||||
? `${competition.revision}:${teamView.revision}`
|
||||
: null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!revisionMismatchKey) {
|
||||
lastAutoRefetchedMismatchRef.current = null;
|
||||
return;
|
||||
}
|
||||
if (
|
||||
hasQueryError ||
|
||||
isRefetching ||
|
||||
lastAutoRefetchedMismatchRef.current === revisionMismatchKey
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastAutoRefetchedMismatchRef.current = revisionMismatchKey;
|
||||
void Promise.all([refetchCompetition(), refetchTeam()]).catch(
|
||||
() => undefined,
|
||||
);
|
||||
}, [
|
||||
hasQueryError,
|
||||
isRefetching,
|
||||
refetchCompetition,
|
||||
refetchTeam,
|
||||
revisionMismatchKey,
|
||||
]);
|
||||
|
||||
function retryBoth() {
|
||||
void Promise.all([refetchCompetition(), refetchTeam()]).catch(
|
||||
() => undefined,
|
||||
);
|
||||
}
|
||||
|
||||
if (competitionQuery.isLoading || teamQuery.isLoading) {
|
||||
return <TeamProgressLoadingState />;
|
||||
}
|
||||
|
||||
if (hasQueryError) {
|
||||
return (
|
||||
<main
|
||||
className="mx-auto max-w-5xl space-y-3 px-4 py-12 sm:px-6"
|
||||
aria-busy="true"
|
||||
aria-label="팀 진행 정보를 불러오는 중"
|
||||
>
|
||||
<div className="h-7 w-48 animate-pulse bg-base-200" />
|
||||
<div className="h-32 animate-pulse bg-base-200/70" />
|
||||
</main>
|
||||
<TeamProgressProblemState
|
||||
content={getTeamProgressErrorContent(
|
||||
[competitionQuery.error, teamQuery.error].filter(Boolean),
|
||||
)}
|
||||
isRetrying={isRefetching}
|
||||
matchId={id}
|
||||
onRetry={retryBoth}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const competition = competitionQuery.data;
|
||||
const teamView = teamQuery.data;
|
||||
if (!competition || !teamView) {
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">팀 진행 정보를 볼 수 없습니다</h1>
|
||||
<p className="mt-2 text-sm text-base-content/45">
|
||||
이 내전에 참여한 계정으로 로그인했는지 확인해주세요.
|
||||
</p>
|
||||
<Link to={`/match/${id}`} className="btn btn-primary btn-sm mt-5">
|
||||
내전 상세로
|
||||
</Link>
|
||||
</main>
|
||||
<TeamProgressProblemState
|
||||
content={getTeamProgressErrorContent([])}
|
||||
isRetrying={isRefetching}
|
||||
matchId={id}
|
||||
onRetry={retryBoth}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!revisionsMatch) {
|
||||
return (
|
||||
<TeamProgressProblemState
|
||||
content={{
|
||||
kind: "unknown",
|
||||
title: isRefetching
|
||||
? "최신 경기 정보를 맞추는 중입니다"
|
||||
: "경기 정보의 revision이 일치하지 않습니다",
|
||||
description: isRefetching
|
||||
? "Competition과 팀 정보를 함께 다시 불러오고 있습니다."
|
||||
: "일관된 경기 정보를 표시할 수 없어 두 응답을 다시 확인해야 합니다.",
|
||||
}}
|
||||
isRetrying={isRefetching}
|
||||
matchId={id}
|
||||
onRetry={retryBoth}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,6 +279,59 @@ export default function MatchTeamProgressPage() {
|
||||
);
|
||||
}
|
||||
|
||||
function TeamProgressLoadingState() {
|
||||
return (
|
||||
<main
|
||||
className="mx-auto max-w-5xl space-y-3 px-4 py-12 sm:px-6"
|
||||
aria-busy="true"
|
||||
aria-label="팀 진행 정보를 불러오는 중"
|
||||
>
|
||||
<div className="h-7 w-48 animate-pulse bg-base-200" />
|
||||
<div className="h-32 animate-pulse bg-base-200/70" />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function TeamProgressProblemState({
|
||||
content,
|
||||
isRetrying,
|
||||
matchId,
|
||||
onRetry,
|
||||
}: {
|
||||
content: TeamProgressErrorContent;
|
||||
isRetrying: boolean;
|
||||
matchId: string | undefined;
|
||||
onRetry: () => void;
|
||||
}) {
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-20 sm:px-6">
|
||||
<section
|
||||
role="alert"
|
||||
aria-busy={isRetrying}
|
||||
className="border border-base-content/10 bg-base-100 px-5 py-8 text-center"
|
||||
>
|
||||
<h1 className="text-lg font-bold">{content.title}</h1>
|
||||
<p className="mt-2 text-sm text-base-content/45">
|
||||
{content.description}
|
||||
</p>
|
||||
<div className="mt-5 flex flex-wrap justify-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm"
|
||||
disabled={isRetrying}
|
||||
onClick={onRetry}
|
||||
>
|
||||
{isRetrying ? "다시 불러오는 중..." : "다시 시도"}
|
||||
</button>
|
||||
<Link to={`/match/${matchId}`} className="btn btn-ghost btn-sm">
|
||||
내전 상세로
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function EmptyState({ message }: { message: string }) {
|
||||
return (
|
||||
<p
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import type {
|
||||
MatchDetailResponse,
|
||||
MatchGameMode,
|
||||
MatchScheduleItemView,
|
||||
} from '@lolympus/contracts';
|
||||
import { Link, useParams } from 'react-router';
|
||||
import {
|
||||
useCreateMatch,
|
||||
@@ -8,12 +13,7 @@ import {
|
||||
useMe,
|
||||
useUpdateMatch,
|
||||
} from '../../api/hooks';
|
||||
import type {
|
||||
ApiMatch,
|
||||
ApiMatchScheduleItem,
|
||||
MatchGameMode,
|
||||
MatchMutationRequest,
|
||||
} from '../../api/types';
|
||||
import type { MatchMutationRequest } from '../../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
||||
|
||||
const DEFAULT_FORM: MatchMutationRequest = {
|
||||
@@ -92,7 +92,7 @@ function parseLines(value: string) {
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function parseSchedule(value: string): ApiMatchScheduleItem[] {
|
||||
function parseSchedule(value: string): MatchScheduleItemView[] {
|
||||
return parseLines(value).map((line) => {
|
||||
const [time, ...labelParts] = line.split('|').map((part) => part.trim());
|
||||
return {
|
||||
@@ -102,11 +102,11 @@ function parseSchedule(value: string): ApiMatchScheduleItem[] {
|
||||
});
|
||||
}
|
||||
|
||||
function scheduleToText(schedule: ApiMatchScheduleItem[] = []) {
|
||||
function scheduleToText(schedule: MatchScheduleItemView[] = []) {
|
||||
return schedule.map((item) => `${item.time}|${item.label}`).join('\n');
|
||||
}
|
||||
|
||||
function makeForm(match?: ApiMatch): MatchMutationRequest & {
|
||||
function makeForm(match?: MatchDetailResponse): MatchMutationRequest & {
|
||||
prizesText: string;
|
||||
noticesText: string;
|
||||
scheduleText: string;
|
||||
@@ -149,7 +149,7 @@ export default function MatchAdminPage() {
|
||||
const createMutation = useCreateMatch(communityId);
|
||||
const updateMutation = useUpdateMatch(communityId);
|
||||
const deleteMutation = useDeleteMatch(communityId);
|
||||
const [editing, setEditing] = useState<ApiMatch | null>(null);
|
||||
const [editing, setEditing] = useState<MatchDetailResponse | null>(null);
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [form, setForm] = useState(makeForm());
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
@@ -181,7 +181,7 @@ export default function MatchAdminPage() {
|
||||
setMessage(null);
|
||||
}
|
||||
|
||||
function openEdit(match: ApiMatch) {
|
||||
function openEdit(match: MatchDetailResponse) {
|
||||
setEditing(match);
|
||||
setForm(makeForm(match));
|
||||
setShowForm(true);
|
||||
@@ -550,7 +550,15 @@ export default function MatchAdminPage() {
|
||||
<button
|
||||
type="button"
|
||||
className="text-xs px-2 py-1 border border-red-500/20 text-red-400 hover:bg-red-500/10"
|
||||
disabled={deleteMutation.isPending}
|
||||
disabled={
|
||||
deleteMutation.isPending ||
|
||||
match.status !== 'recruiting'
|
||||
}
|
||||
title={
|
||||
match.status === 'recruiting'
|
||||
? '내전 삭제'
|
||||
: '팀 구성이 확정된 내전 기록은 삭제할 수 없습니다.'
|
||||
}
|
||||
onClick={() => {
|
||||
if (!window.confirm('이 내전을 삭제할까요?')) return;
|
||||
deleteMutation.mutate(match._id, {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
interface RevisionedSnapshot {
|
||||
revision: number;
|
||||
}
|
||||
|
||||
export type TeamProgressErrorContent = {
|
||||
kind:
|
||||
| "unauthorized"
|
||||
| "forbidden"
|
||||
| "not-found"
|
||||
| "not-ready"
|
||||
| "server"
|
||||
| "network"
|
||||
| "unknown";
|
||||
title: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
export function isConsistentTeamProgressSnapshot(
|
||||
competition: RevisionedSnapshot | null | undefined,
|
||||
teamView: RevisionedSnapshot | null | undefined,
|
||||
): boolean {
|
||||
return Boolean(
|
||||
competition &&
|
||||
teamView &&
|
||||
competition.revision === teamView.revision,
|
||||
);
|
||||
}
|
||||
|
||||
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] : [];
|
||||
});
|
||||
|
||||
if (statuses.includes(401)) {
|
||||
return {
|
||||
kind: "unauthorized",
|
||||
title: "로그인이 필요합니다",
|
||||
description: "팀 진행 정보를 보려면 로그인한 뒤 다시 시도해 주세요.",
|
||||
};
|
||||
}
|
||||
if (statuses.includes(403)) {
|
||||
return {
|
||||
kind: "forbidden",
|
||||
title: "팀 진행 정보를 볼 권한이 없습니다",
|
||||
description:
|
||||
"이 내전에 참여한 팀원 계정으로 로그인했는지 확인해 주세요.",
|
||||
};
|
||||
}
|
||||
if (statuses.includes(404)) {
|
||||
return {
|
||||
kind: "not-found",
|
||||
title: "팀 진행 정보를 찾을 수 없습니다",
|
||||
description: "내전이 삭제되었거나 Competition이 아직 준비되지 않았습니다.",
|
||||
};
|
||||
}
|
||||
if (statuses.includes(409)) {
|
||||
return {
|
||||
kind: "not-ready",
|
||||
title: "Competition이 아직 준비되지 않았습니다",
|
||||
description: "팀 구성이 완료된 뒤 다시 시도해 주세요.",
|
||||
};
|
||||
}
|
||||
if (statuses.some((status) => status >= 500 && status <= 599)) {
|
||||
return {
|
||||
kind: "server",
|
||||
title: "서버에서 팀 진행 정보를 불러오지 못했습니다",
|
||||
description: "잠시 후 다시 시도해 주세요.",
|
||||
};
|
||||
}
|
||||
if (errors.some(isNetworkError)) {
|
||||
return {
|
||||
kind: "network",
|
||||
title: "네트워크에 연결할 수 없습니다",
|
||||
description: "인터넷 연결을 확인한 뒤 다시 시도해 주세요.",
|
||||
};
|
||||
}
|
||||
return {
|
||||
kind: "unknown",
|
||||
title: "팀 진행 정보를 불러오지 못했습니다",
|
||||
description: "일시적인 오류일 수 있습니다. 다시 시도해 주세요.",
|
||||
};
|
||||
}
|
||||
|
||||
function isNetworkError(error: unknown): boolean {
|
||||
return (
|
||||
error instanceof TypeError ||
|
||||
(error instanceof Error && error.name === "TypeError")
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user