From 96bae0ce2861aefe146814c34201157a6ed0f6cd Mon Sep 17 00:00:00 2001 From: Park Dahyeon Date: Tue, 14 Jul 2026 03:22:33 +0000 Subject: [PATCH] feat(web): add match detail tabs --- .../competition/CompetitionResults.tsx | 42 ++- .../competition/MatchDetailTabBar.tsx | 104 ++++++++ .../competition/match-detail-tabs.ts | 83 ++++++ apps/web/src/pages/MatchDetailPage.tsx | 246 ++++++++++++++++-- apps/web/test/match-detail-tabs.test.ts | 77 ++++++ 5 files changed, 523 insertions(+), 29 deletions(-) create mode 100644 apps/web/src/components/competition/MatchDetailTabBar.tsx create mode 100644 apps/web/src/components/competition/match-detail-tabs.ts create mode 100644 apps/web/test/match-detail-tabs.test.ts diff --git a/apps/web/src/components/competition/CompetitionResults.tsx b/apps/web/src/components/competition/CompetitionResults.tsx index d1530d6f..9a83983f 100644 --- a/apps/web/src/components/competition/CompetitionResults.tsx +++ b/apps/web/src/components/competition/CompetitionResults.tsx @@ -7,6 +7,7 @@ import type { import { Link } from "react-router"; import { CompetitionSeriesHistory } from "./CompetitionSeriesHistory"; import { DoubleEliminationBracket } from "./DoubleEliminationBracket"; +import { createCompetitionSeriesHistory } from "./competition-series-history"; import { createCompetitionBracketLayout } from "./competition-display-layout"; import { bracketRoundLabel } from "./double-elimination-bracket-layout"; import { RoundRobinTable } from "./RoundRobinTable"; @@ -14,13 +15,40 @@ import { SeriesScoreCard } from "./SeriesScoreCard"; export function CompetitionResults({ competition, + view = "all", }: { competition: CompetitionDetailResponse; + view?: "all" | "bracket" | "games"; }) { const { projection } = competition; const teamById = new Map( competition.teams.map((team) => [team.teamId, team]), ); + + if (view === "games") { + const hasSeriesHistory = + createCompetitionSeriesHistory(projection).length > 0; + return ( +
+ {hasSeriesHistory ? ( + + ) : ( +

+ 기록된 공식 경기가 없습니다. +

+ )} +
+ ); + } + const seriesById = new Map( projection.series.map((series) => [series.seriesId, series]), ); @@ -82,12 +110,14 @@ export function CompetitionResults({

)} - + {view === "all" && ( + + )} ); } diff --git a/apps/web/src/components/competition/MatchDetailTabBar.tsx b/apps/web/src/components/competition/MatchDetailTabBar.tsx new file mode 100644 index 00000000..29e70aaf --- /dev/null +++ b/apps/web/src/components/competition/MatchDetailTabBar.tsx @@ -0,0 +1,104 @@ +import { useEffect, useRef } from "react"; +import { + moveMatchDetailTabFocus, + type MatchDetailTab, + type MatchDetailTabId, + type MatchDetailTabNavigationKey, +} from "./match-detail-tabs"; + +export function MatchDetailTabBar({ + tabs, + activeTab, + onChange, +}: { + tabs: readonly MatchDetailTab[]; + activeTab: MatchDetailTabId; + onChange: (tab: MatchDetailTabId) => void; +}) { + const tabRefs = useRef< + Partial> + >({}); + const previousActiveTabRef = useRef(activeTab); + + useEffect(() => { + tabRefs.current[activeTab]?.scrollIntoView({ + block: "nearest", + inline: "nearest", + }); + if (previousActiveTabRef.current === activeTab) return; + + const activePanel = document.getElementById( + `match-detail-panel-${activeTab}`, + ); + const panelTop = activePanel?.getBoundingClientRect().top; + if ( + activePanel && + panelTop !== undefined && + (panelTop < 96 || panelTop >= window.innerHeight) + ) { + activePanel.scrollIntoView({ block: "start" }); + } + previousActiveTabRef.current = activeTab; + }, [activeTab]); + + function handleKeyDown( + event: React.KeyboardEvent, + currentTab: MatchDetailTabId, + ) { + if (!isNavigationKey(event.key)) return; + const nextTab = moveMatchDetailTabFocus(tabs, currentTab, event.key); + if (!nextTab) return; + + event.preventDefault(); + onChange(nextTab); + window.requestAnimationFrame(() => tabRefs.current[nextTab]?.focus()); + } + + return ( +
+
+ {tabs.map((tab) => { + const selected = activeTab === tab.id; + return ( + + ); + })} +
+
+ ); +} + +function isNavigationKey( + key: string, +): key is MatchDetailTabNavigationKey { + return ( + key === "ArrowLeft" || + key === "ArrowRight" || + key === "Home" || + key === "End" + ); +} diff --git a/apps/web/src/components/competition/match-detail-tabs.ts b/apps/web/src/components/competition/match-detail-tabs.ts new file mode 100644 index 00000000..44d97153 --- /dev/null +++ b/apps/web/src/components/competition/match-detail-tabs.ts @@ -0,0 +1,83 @@ +export type MatchDetailTabStatus = + | "recruiting" + | "team-built" + | "in-progress" + | "finished"; + +export type MatchDetailTabId = + | "bracket" + | "games" + | "teams" + | "info" + | "ops"; + +export type MatchDetailTab = { + id: MatchDetailTabId; + label: string; +}; + +export type MatchDetailTabNavigationKey = + | "ArrowLeft" + | "ArrowRight" + | "Home" + | "End"; + +export const MATCH_DETAIL_TAB_QUERY_KEY = "tab"; + +const PUBLIC_MATCH_DETAIL_TABS: MatchDetailTab[] = [ + { id: "bracket", label: "대진표·순위" }, + { id: "games", label: "경기 기록" }, + { id: "teams", label: "팀" }, + { id: "info", label: "일정·안내" }, +]; + +const OPERATIONS_TAB: MatchDetailTab = { id: "ops", label: "운영" }; + +export function createMatchDetailTabs({ + status, + canManage, +}: { + status: MatchDetailTabStatus; + canManage: boolean; +}): MatchDetailTab[] { + if (status !== "in-progress" && status !== "finished") return []; + return canManage + ? [...PUBLIC_MATCH_DETAIL_TABS, OPERATIONS_TAB] + : [...PUBLIC_MATCH_DETAIL_TABS]; +} + +export function resolveMatchDetailTab( + requestedTab: string | null | undefined, + availableTabs: readonly MatchDetailTab[], +): MatchDetailTabId | null { + return ( + availableTabs.find((tab) => tab.id === requestedTab)?.id ?? + availableTabs[0]?.id ?? + null + ); +} + +export function createMatchDetailTabSearchParams( + current: URLSearchParams, + nextTab: MatchDetailTabId, +): URLSearchParams { + const next = new URLSearchParams(current); + next.set(MATCH_DETAIL_TAB_QUERY_KEY, nextTab); + return next; +} + +export function moveMatchDetailTabFocus( + tabs: readonly MatchDetailTab[], + currentTab: MatchDetailTabId, + key: MatchDetailTabNavigationKey, +): MatchDetailTabId | null { + if (tabs.length === 0) return null; + if (key === "Home") return tabs[0].id; + if (key === "End") return tabs[tabs.length - 1].id; + + const currentIndex = tabs.findIndex((tab) => tab.id === currentTab); + const safeIndex = currentIndex === -1 ? 0 : currentIndex; + const direction = key === "ArrowRight" ? 1 : -1; + const nextIndex = (safeIndex + direction + tabs.length) % tabs.length; + return tabs[nextIndex].id; +} diff --git a/apps/web/src/pages/MatchDetailPage.tsx b/apps/web/src/pages/MatchDetailPage.tsx index 6f2b5a01..11c31ace 100644 --- a/apps/web/src/pages/MatchDetailPage.tsx +++ b/apps/web/src/pages/MatchDetailPage.tsx @@ -5,7 +5,13 @@ import type { MatchParticipantView, } from "@lolympus/contracts"; import { ChevronLeft, Search, X } from "lucide-react"; -import { Link, useLocation, useNavigate, useParams } from "react-router"; +import { + Link, + useLocation, + useNavigate, + useParams, + useSearchParams, +} from "react-router"; import { useAuction, useCollectTournamentResultByRiotMatch, @@ -28,7 +34,14 @@ import { import { RankBadge } from "../components/RankBadge"; import { CompetitionAdminControls } from "../components/competition/CompetitionAdminControls"; import { CompetitionResults } from "../components/competition/CompetitionResults"; +import { MatchDetailTabBar } from "../components/competition/MatchDetailTabBar"; import { MATCH_PAGE_MAX_WIDTH_CLASS } from "../components/competition/competition-display-layout"; +import { + createMatchDetailTabSearchParams, + createMatchDetailTabs, + resolveMatchDetailTab, + type MatchDetailTabId, +} from "../components/competition/match-detail-tabs"; import { DEFAULT_COMMUNITY_ID, useAuthUserId } from "../config"; import { apiFetch, ApiError } from "../lib/api"; import { profileIconUrl } from "../lib/ddragon"; @@ -1383,6 +1396,7 @@ function formatManualCollectSummary( export default function MatchDetailPage() { const { id } = useParams(); const navigate = useNavigate(); + const [searchParams, setSearchParams] = useSearchParams(); const queryClient = useQueryClient(); const authUserId = useAuthUserId(); const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID); @@ -1401,6 +1415,10 @@ export default function MatchDetailPage() { meQuery.data?.memberships.find( (membership) => membership.community?._id === DEFAULT_COMMUNITY_ID, )?.user ?? null; + const canManageAuction = + currentUser?.role === "owner" || currentUser?.role === "admin"; + const isCheckingPermissions = + meQuery.isLoading || (meQuery.isFetching && !meQuery.data); const canUseMemberActions = Boolean(currentUser || authUserId); const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID); const [captainSelections, setCaptainSelections] = useState< @@ -1702,6 +1720,33 @@ export default function MatchDetailPage() { return () => window.clearTimeout(timer); }, [matchQuery.data?.participants]); + useEffect(() => { + const status = matchQuery.data?.status; + const requestedTab = searchParams.get("tab"); + if ( + isCheckingPermissions || + !requestedTab || + (status !== "in-progress" && status !== "finished") + ) return; + + const resolvedTab = resolveMatchDetailTab( + requestedTab, + createMatchDetailTabs({ status, canManage: canManageAuction }), + ); + if (!resolvedTab || resolvedTab === requestedTab) return; + + setSearchParams( + createMatchDetailTabSearchParams(searchParams, resolvedTab), + { replace: true, preventScrollReset: true }, + ); + }, [ + canManageAuction, + isCheckingPermissions, + matchQuery.data?.status, + searchParams, + setSearchParams, + ]); + if (!DEFAULT_COMMUNITY_ID) { return (
@@ -1735,10 +1780,6 @@ export default function MatchDetailPage() { const match = mapApiMatchToMatchDetail(matchQuery.data); const si = statusBadge(match.status); - const canManageAuction = - currentUser?.role === "owner" || currentUser?.role === "admin"; - const isCheckingPermissions = - meQuery.isLoading || (meQuery.isFetching && !meQuery.data); const auctionNotStarted = auctionQuery.error instanceof ApiError && auctionQuery.error.status === 404; const activeAuction = auctionNotStarted ? null : auctionQuery.data; @@ -1792,6 +1833,60 @@ export default function MatchDetailPage() { hasValidCaptainInitialPoints && hasValidAuctionTimerSettings; + const matchTabs = createMatchDetailTabs({ + status: match.status, + canManage: canManageAuction, + }); + const activeMatchTab = resolveMatchDetailTab( + searchParams.get("tab"), + matchTabs, + ); + const usesTabbedLayout = activeMatchTab !== null; + const showCompetitionState = + !usesTabbedLayout || + activeMatchTab === "bracket" || + activeMatchTab === "games" || + activeMatchTab === "ops"; + const showCompetitionResults = + !usesTabbedLayout || + activeMatchTab === "bracket" || + activeMatchTab === "games"; + const showOperationsPanel = + !usesTabbedLayout || activeMatchTab === "ops"; + const showTeamsPanel = !usesTabbedLayout || activeMatchTab === "teams"; + const showInfoPanel = !usesTabbedLayout || activeMatchTab === "info"; + const hasMatchInfo = + match.schedule.length > 0 || + match.prizes.length > 0 || + match.notices.length > 0; + const showSupportingLayout = + !usesTabbedLayout || + showTeamsPanel || + showInfoPanel || + (showOperationsPanel && match.status === "in-progress"); + const showEmptyOperationsState = + usesTabbedLayout && + activeMatchTab === "ops" && + match.status === "finished" && + !competitionQuery.isLoading && + !competitionQuery.error && + (!competitionEnabled || + competitionQuery.data?.projection.series.length === 0); + const supportingAsideClassName = usesTabbedLayout + ? showInfoPanel + ? "grid w-full gap-4 lg:grid-cols-2" + : showOperationsPanel + ? "w-full space-y-4 lg:max-w-sm" + : "hidden" + : "w-full lg:w-64 shrink-0 space-y-4"; + + function handleMatchDetailTabChange(nextTab: MatchDetailTabId) { + setSearchParams( + createMatchDetailTabSearchParams(searchParams, nextTab), + { preventScrollReset: true }, + ); + } + return (
)} - {competitionQuery.isLoading && competitionEnabled && ( + {usesTabbedLayout && activeMatchTab && ( + + )} + + {usesTabbedLayout && + activeMatchTab && + matchTabs + .filter((tab) => tab.id !== activeMatchTab) + .map((tab) => ( +
); } diff --git a/apps/web/test/match-detail-tabs.test.ts b/apps/web/test/match-detail-tabs.test.ts new file mode 100644 index 00000000..019abf66 --- /dev/null +++ b/apps/web/test/match-detail-tabs.test.ts @@ -0,0 +1,77 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { + createMatchDetailTabSearchParams, + createMatchDetailTabs, + moveMatchDetailTabFocus, + resolveMatchDetailTab, +} from "../src/components/competition/match-detail-tabs.ts"; + +test("uses tabs only in progress or when finished and exposes operations only to managers", () => { + assert.deepEqual( + createMatchDetailTabs({ status: "recruiting", canManage: true }), + [], + ); + assert.deepEqual( + createMatchDetailTabs({ status: "team-built", canManage: true }), + [], + ); + + const publicTabs = createMatchDetailTabs({ + status: "in-progress", + canManage: false, + }); + assert.deepEqual( + publicTabs.map((tab) => tab.id), + ["bracket", "games", "teams", "info"], + ); + assert.deepEqual( + publicTabs.map((tab) => tab.label), + ["대진표·순위", "경기 기록", "팀", "일정·안내"], + ); + + const managerTabs = createMatchDetailTabs({ + status: "finished", + canManage: true, + }); + assert.deepEqual( + managerTabs.map((tab) => tab.id), + ["bracket", "games", "teams", "info", "ops"], + ); +}); + +test("falls back to the bracket for missing, invalid, or unauthorized tabs", () => { + const publicTabs = createMatchDetailTabs({ + status: "in-progress", + canManage: false, + }); + + assert.equal(resolveMatchDetailTab(null, []), null); + assert.equal(resolveMatchDetailTab(null, publicTabs), "bracket"); + assert.equal(resolveMatchDetailTab("unknown", publicTabs), "bracket"); + assert.equal(resolveMatchDetailTab("ops", publicTabs), "bracket"); + assert.equal(resolveMatchDetailTab("games", publicTabs), "games"); +}); + +test("updates the tab query without mutating or dropping unrelated parameters", () => { + const current = new URLSearchParams("season=2026&tab=teams&from=history"); + const next = createMatchDetailTabSearchParams(current, "games"); + + assert.equal(next.get("tab"), "games"); + assert.equal(next.get("season"), "2026"); + assert.equal(next.get("from"), "history"); + assert.equal(current.get("tab"), "teams"); +}); + +test("moves tab focus with wrapping arrow keys and boundary keys", () => { + const tabs = createMatchDetailTabs({ + status: "in-progress", + canManage: false, + }); + + assert.equal(moveMatchDetailTabFocus(tabs, "bracket", "ArrowRight"), "games"); + assert.equal(moveMatchDetailTabFocus(tabs, "bracket", "ArrowLeft"), "info"); + assert.equal(moveMatchDetailTabFocus(tabs, "info", "ArrowRight"), "bracket"); + assert.equal(moveMatchDetailTabFocus(tabs, "teams", "Home"), "bracket"); + assert.equal(moveMatchDetailTabFocus(tabs, "games", "End"), "info"); +});