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;
}
+223 -23
View File
@@ -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 (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
@@ -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 (
<main
className={`mx-auto px-4 py-6 sm:px-6 ${
@@ -1877,7 +1972,59 @@ export default function MatchDetailPage() {
</div>
)}
{competitionQuery.isLoading && competitionEnabled && (
{usesTabbedLayout && activeMatchTab && (
<MatchDetailTabBar
tabs={matchTabs}
activeTab={activeMatchTab}
onChange={handleMatchDetailTabChange}
/>
)}
{usesTabbedLayout &&
activeMatchTab &&
matchTabs
.filter((tab) => tab.id !== activeMatchTab)
.map((tab) => (
<div
key={tab.id}
id={`match-detail-panel-${tab.id}`}
role="tabpanel"
aria-labelledby={`match-detail-tab-${tab.id}`}
hidden
/>
))}
<div
id={
usesTabbedLayout && activeMatchTab
? `match-detail-panel-${activeMatchTab}`
: undefined
}
role={usesTabbedLayout ? "tabpanel" : undefined}
aria-labelledby={
usesTabbedLayout && activeMatchTab
? `match-detail-tab-${activeMatchTab}`
: undefined
}
tabIndex={usesTabbedLayout ? 0 : undefined}
className={
usesTabbedLayout
? "scroll-mt-24 pt-5 focus-visible:outline-none"
: undefined
}
>
{usesTabbedLayout &&
showCompetitionResults &&
!competitionEnabled && (
<div
className="mb-6 border border-dashed border-base-content/15 bg-base-content/[0.02] px-4 py-5 text-sm text-base-content/45"
role="status"
>
공식 경기 결과가 아직 준비되지 않았습니다.
</div>
)}
{showCompetitionState && competitionQuery.isLoading && competitionEnabled && (
<div
className="mb-6 space-y-3 border border-base-content/10 p-4"
aria-busy="true"
@@ -1888,7 +2035,8 @@ export default function MatchDetailPage() {
</div>
)}
{competitionQuery.error &&
{showCompetitionState &&
competitionQuery.error &&
!(
competitionQuery.error instanceof ApiError &&
competitionQuery.error.status === 404
@@ -1898,18 +2046,32 @@ export default function MatchDetailPage() {
</div>
)}
{competitionEnabled && competitionQuery.data && (
{showCompetitionState && competitionEnabled && competitionQuery.data && (
<>
<CompetitionResults competition={competitionQuery.data} />
<CompetitionAdminControls
competition={competitionQuery.data}
communityId={DEFAULT_COMMUNITY_ID}
canManage={canManageAuction}
/>
{showCompetitionResults && (
<CompetitionResults
competition={competitionQuery.data}
view={
usesTabbedLayout
? activeMatchTab === "games"
? "games"
: "bracket"
: "all"
}
/>
)}
{showOperationsPanel && (
<CompetitionAdminControls
competition={competitionQuery.data}
communityId={DEFAULT_COMMUNITY_ID}
canManage={canManageAuction}
/>
)}
</>
)}
{competitionEnabled &&
{showCompetitionState &&
competitionEnabled &&
competitionQuery.error instanceof ApiError &&
competitionQuery.error.status === 404 && (
<div
@@ -1920,8 +2082,23 @@ export default function MatchDetailPage() {
</div>
)}
<div className="flex flex-col lg:flex-row gap-5">
<div className="flex-1 min-w-0 space-y-4">
{showEmptyOperationsState && (
<div
className="mb-6 border border-dashed border-base-content/15 px-4 py-8 text-center text-sm text-base-content/40"
role="status"
>
운영할 공식 경기 데이터가 없습니다.
</div>
)}
{showSupportingLayout && (
<div
className={
usesTabbedLayout ? "block" : "flex flex-col lg:flex-row gap-5"
}
>
{showTeamsPanel && (
<div className="flex-1 min-w-0 space-y-4">
{match.status === "recruiting" ? (
<>
<ParticipantTable
@@ -2298,6 +2475,16 @@ export default function MatchDetailPage() {
</>
) : (
<div className="space-y-4">
{usesTabbedLayout &&
showTeamsPanel &&
match.teams.length === 0 && (
<div
className="border border-dashed border-base-content/15 px-4 py-8 text-center text-sm text-base-content/40"
role="status"
>
등록된 팀이 없습니다.
</div>
)}
{match.teams.map((team) => (
<TeamCard key={team.teamIndex} team={team} />
))}
@@ -2313,10 +2500,20 @@ export default function MatchDetailPage() {
)}
</div>
)}
</div>
</div>
)}
<div className="w-full lg:w-64 shrink-0 space-y-4">
{match.schedule.length > 0 && (
<div className={supportingAsideClassName}>
{usesTabbedLayout && showInfoPanel && !hasMatchInfo && (
<div
className="lg:col-span-2 border border-dashed border-base-content/15 px-4 py-8 text-center text-sm text-base-content/40"
role="status"
>
등록된 일정이나 안내가 없습니다.
</div>
)}
{showInfoPanel && match.schedule.length > 0 && (
<SideCard title="일정">
<ul className="space-y-2">
{match.schedule.map((item, index) => (
@@ -2331,7 +2528,8 @@ export default function MatchDetailPage() {
</SideCard>
)}
{canManageAuction &&
{showOperationsPanel &&
canManageAuction &&
(match.status === "team-built" ||
match.status === "in-progress") && (
<SideCard title="결과 수집">
@@ -2449,7 +2647,7 @@ export default function MatchDetailPage() {
</SideCard>
)}
{match.prizes.length > 0 && (
{showInfoPanel && match.prizes.length > 0 && (
<SideCard title="상품">
<ul className="space-y-1.5">
{match.prizes.map((prize, index) => (
@@ -2465,7 +2663,7 @@ export default function MatchDetailPage() {
</SideCard>
)}
{match.notices.length > 0 && (
{showInfoPanel && match.notices.length > 0 && (
<SideCard title="안내사항">
<ul className="space-y-1.5">
{match.notices.map((notice, index) => (
@@ -2482,6 +2680,8 @@ export default function MatchDetailPage() {
)}
</div>
</div>
)}
</div>
</main>
);
}