feat(web): add match detail tabs

This commit is contained in:
dahyeon committed 2026-07-14 03:22:33 +00:00
1 parent a88562b208
commit 96bae0ce28
5 files changed
+523 -29

No files matched your search

@@ -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 (
<div className="mb-6">
{hasSeriesHistory ? (
<CompetitionSeriesHistory
communityId={competition.communityId}
matchId={competition.matchId}
projection={projection}
teamById={teamById}
/>
) : (
<p
className="border border-dashed border-base-content/15 px-4 py-8 text-center text-sm text-base-content/45"
role="status"
>
기록된 공식 경기가 없습니다.
</p>
)}
</div>
);
}
const seriesById = new Map(
projection.series.map((series) => [series.seriesId, series]),
);
@@ -82,12 +110,14 @@ export function CompetitionResults({
</p>
)}
<CompetitionSeriesHistory
communityId={competition.communityId}
matchId={competition.matchId}
projection={projection}
teamById={teamById}
/>
{view === "all" && (
<CompetitionSeriesHistory
communityId={competition.communityId}
matchId={competition.matchId}
projection={projection}
teamById={teamById}
/>
)}
</section>
);
}
@@ -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<Record<MatchDetailTabId, HTMLButtonElement | null>>
>({});
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<HTMLButtonElement>,
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 (
<div className="sticky top-12 z-40 -mx-4 border-y border-base-content/10 bg-base-100/95 px-4 backdrop-blur sm:-mx-6 sm:px-6">
<div
className="flex overflow-x-auto"
role="tablist"
aria-label="내전 상세"
>
{tabs.map((tab) => {
const selected = activeTab === tab.id;
return (
<button
key={tab.id}
ref={(element) => {
tabRefs.current[tab.id] = element;
}}
id={`match-detail-tab-${tab.id}`}
type="button"
role="tab"
aria-selected={selected}
aria-controls={`match-detail-panel-${tab.id}`}
tabIndex={selected ? 0 : -1}
onClick={() => onChange(tab.id)}
onKeyDown={(event) => handleKeyDown(event, tab.id)}
className={`min-h-11 flex-none whitespace-nowrap border-b-2 px-4 text-xs font-bold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${
selected
? "border-primary bg-primary/5 text-primary"
: "border-transparent text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
}`}
>
{tab.label}
</button>
);
})}
</div>
</div>
);
}
function isNavigationKey(
key: string,
): key is MatchDetailTabNavigationKey {
return (
key === "ArrowLeft" ||
key === "ArrowRight" ||
key === "Home" ||
key === "End"
);
}
@@ -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;
}