feat(web): show winning teams in recent match results
This commit is contained in:
1 parent
664af15255
commit
20e1e6ec04
1 file changed
+149
-49
+149
-49
@@ -4,7 +4,7 @@ import type {
|
|||||||
MatchEventType,
|
MatchEventType,
|
||||||
MatchSummaryResponse,
|
MatchSummaryResponse,
|
||||||
} from '@lolympus/contracts';
|
} from '@lolympus/contracts';
|
||||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
import { ChevronLeft, ChevronRight, Trophy } from 'lucide-react';
|
||||||
import { Link, useSearchParams } from 'react-router';
|
import { Link, useSearchParams } from 'react-router';
|
||||||
import {
|
import {
|
||||||
useCommunityLeaderboard,
|
useCommunityLeaderboard,
|
||||||
@@ -172,29 +172,12 @@ function UpcomingMatches({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function HistoryResult({
|
function HistoryResult({ match }: { match: MatchSummaryResponse }) {
|
||||||
match,
|
|
||||||
showTeamNames = false,
|
|
||||||
}: {
|
|
||||||
match: MatchSummaryResponse;
|
|
||||||
showTeamNames?: boolean;
|
|
||||||
}) {
|
|
||||||
const result = match.historyResult;
|
const result = match.historyResult;
|
||||||
const teamLabelClass = `min-w-0 break-words text-content-muted${showTeamNames ? '' : ' md:truncate'}`;
|
const teamLabelClass = 'min-w-0 break-words text-content-muted md:truncate';
|
||||||
if (match.status === 'finished' && result) {
|
if (match.status === 'finished' && result) {
|
||||||
switch (result.type) {
|
switch (result.type) {
|
||||||
case 'score': {
|
case 'score': {
|
||||||
if (showTeamNames && result.teamAName && result.teamBName) {
|
|
||||||
return (
|
|
||||||
<span className="break-words text-content">
|
|
||||||
{result.teamAName}{' '}
|
|
||||||
<strong className="tabular whitespace-nowrap font-bold">
|
|
||||||
{result.teamAWins}–{result.teamBWins}
|
|
||||||
</strong>{' '}
|
|
||||||
{result.teamBName}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const label = result.winnerTeamName
|
const label = result.winnerTeamName
|
||||||
? `${result.winnerTeamName} 승`
|
? `${result.winnerTeamName} 승`
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -418,42 +401,76 @@ function RecentMatchResults({ matches }: { matches: MatchSummaryResponse[] }) {
|
|||||||
<ul className="divide-y divide-line border-y border-line">
|
<ul className="divide-y divide-line border-y border-line">
|
||||||
{matches.map((match) => {
|
{matches.map((match) => {
|
||||||
const schedule = getHomeMatchSchedule(match.scheduledAt);
|
const schedule = getHomeMatchSchedule(match.scheduledAt);
|
||||||
const name = getHistoryMatchTitle(match.title, schedule);
|
const name = getHistoryMatchTitle(match.title, schedule).trim();
|
||||||
// 이름이 "내전"뿐이면 행을 구분할 수 없으므로 일정을 제목으로 올린다.
|
const result = match.historyResult;
|
||||||
const datedTitle = schedule && GENERIC_MATCH_NAME.test(name.trim());
|
const winners = getWinnerTeams(match);
|
||||||
const details = [
|
const meta = [
|
||||||
!datedTitle && (schedule?.compact ?? '일정 미정'),
|
schedule?.time,
|
||||||
match.teams.length > 2 && `${match.teams.length}팀`,
|
match.teams.length > 2 && `${match.teams.length}팀`,
|
||||||
match.mapId !== DEFAULT_MAP_ID && mapIdToLabel(match.mapId),
|
match.mapId !== DEFAULT_MAP_ID && mapIdToLabel(match.mapId),
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
const isDraw =
|
||||||
|
result?.type === 'decision'
|
||||||
|
? result.decision === 'draw'
|
||||||
|
: result?.type === 'score' && winners.length === 0;
|
||||||
|
const winnerLabel =
|
||||||
|
result?.type === 'winners'
|
||||||
|
? winners.length > 1
|
||||||
|
? '공동 1위'
|
||||||
|
: '우승'
|
||||||
|
: result?.type === 'decision' && result.decision !== 'draw'
|
||||||
|
? DECISION_LABELS[result.decision]
|
||||||
|
: '승리';
|
||||||
return (
|
return (
|
||||||
<li key={match._id}>
|
<li key={match._id}>
|
||||||
<Link
|
<Link
|
||||||
to={`/match/${match._id}`}
|
to={`/match/${match._id}`}
|
||||||
className="group grid gap-1 px-2 py-3.5 transition-colors hover:bg-sunken focus-visible:-outline-offset-2 md:grid-cols-[minmax(0,1fr)_auto] md:items-center md:gap-4"
|
className={`${RECENT_RESULT_ROW_CLASS} group transition-colors hover:bg-sunken focus-visible:-outline-offset-2`}
|
||||||
>
|
>
|
||||||
<div className="min-w-0">
|
<div className="tabular flex items-baseline gap-2 md:block">
|
||||||
<p className="tabular break-words text-[15px] font-semibold leading-snug text-content group-hover:underline">
|
<p className="text-[15px] font-semibold leading-snug text-content">
|
||||||
{datedTitle ? (
|
{schedule ? (
|
||||||
<>
|
<time dateTime={match.scheduledAt}>
|
||||||
<time dateTime={match.scheduledAt}>{schedule.compact}</time>{' '}
|
{schedule.month}/{schedule.day} ({schedule.weekday})
|
||||||
{name}
|
</time>
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
name
|
'일정 미정'
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
{details.length > 0 && (
|
{meta.length > 0 && (
|
||||||
<p className="tabular mt-0.5 text-xs text-content-muted">
|
<p className="text-xs text-content-muted md:mt-0.5">
|
||||||
{details.join(' · ')}
|
{meta.join(' · ')}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{match.historyResult && (
|
<div className="min-w-0 space-y-2">
|
||||||
<div className="min-w-0 text-[13px] md:text-right">
|
{/* 날짜만으로 구분되는 "내전"은 이름을 반복하지 않는다. */}
|
||||||
<HistoryResult match={match} showTeamNames />
|
{!GENERIC_MATCH_NAME.test(name) && (
|
||||||
</div>
|
<p className="truncate text-xs text-content-muted" title={name}>
|
||||||
)}
|
{name}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{winners.map((team) => (
|
||||||
|
<WinnerTeam key={team.name} team={team} label={winnerLabel} />
|
||||||
|
))}
|
||||||
|
{winners.length === 0 && (
|
||||||
|
<p className="text-sm text-content-muted">
|
||||||
|
{isDraw ? '무승부' : '결과 미집계'}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 md:justify-self-end">
|
||||||
|
{result?.type === 'score' && (
|
||||||
|
<strong className="tabular whitespace-nowrap text-[15px] font-bold text-content">
|
||||||
|
{Math.max(result.teamAWins, result.teamBWins)} :{' '}
|
||||||
|
{Math.min(result.teamAWins, result.teamBWins)}
|
||||||
|
</strong>
|
||||||
|
)}
|
||||||
|
<ChevronRight
|
||||||
|
className="hidden size-4 text-content-muted md:block"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
@@ -462,19 +479,102 @@ function RecentMatchResults({ matches }: { matches: MatchSummaryResponse[] }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RECENT_RESULT_ROW_CLASS =
|
||||||
|
'grid gap-2 px-2 py-3.5 md:grid-cols-[7.5rem_minmax(0,1fr)_auto] md:items-center md:gap-4';
|
||||||
|
const POSITION_ORDER = ['TOP', 'JGL', 'MID', 'ADC', 'SUP'];
|
||||||
|
|
||||||
|
interface WinnerTeamSummary {
|
||||||
|
name: string;
|
||||||
|
members: MatchSummaryResponse['participants'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 결과에 담긴 우승팀 이름을 팀 구성과 맞춰 멤버를 포지션 순으로 돌려준다. */
|
||||||
|
function getWinnerTeams(match: MatchSummaryResponse): WinnerTeamSummary[] {
|
||||||
|
const result = match.historyResult;
|
||||||
|
if (match.status !== 'finished' || !result) return [];
|
||||||
|
const names =
|
||||||
|
result.type === 'winners'
|
||||||
|
? result.teamNames
|
||||||
|
: result.winnerTeamName
|
||||||
|
? [result.winnerTeamName]
|
||||||
|
: [];
|
||||||
|
const participants = new Map(
|
||||||
|
match.participants.map((participant) => [participant.userId, participant]),
|
||||||
|
);
|
||||||
|
return names.map((name) => {
|
||||||
|
// 같은 이름의 팀이 여럿이면 누가 우승했는지 알 수 없으므로 멤버를 비운다.
|
||||||
|
const candidates = match.teams.filter(
|
||||||
|
(team) => (team.name.trim() || `${team.teamIndex}팀`) === name,
|
||||||
|
);
|
||||||
|
const members =
|
||||||
|
candidates.length === 1
|
||||||
|
? [...candidates[0].members]
|
||||||
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
POSITION_ORDER.indexOf(a.assignedPosition) -
|
||||||
|
POSITION_ORDER.indexOf(b.assignedPosition),
|
||||||
|
)
|
||||||
|
.flatMap((member) => {
|
||||||
|
const participant = participants.get(member.userId);
|
||||||
|
return participant ? [participant] : [];
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
return { name, members };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function WinnerTeam({ team, label }: { team: WinnerTeamSummary; label: string }) {
|
||||||
|
const { data: manifest } = useDdragonManifest();
|
||||||
|
const memberNames = team.members
|
||||||
|
.map((member) => member.gameName)
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · ');
|
||||||
|
return (
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="flex min-w-0 items-center gap-1.5">
|
||||||
|
<Trophy className="size-4 shrink-0 text-gold" aria-hidden="true" />
|
||||||
|
<span className="shrink-0 text-xs font-semibold text-gold">{label}</span>
|
||||||
|
<strong className="truncate text-[15px] font-semibold text-content group-hover:underline">
|
||||||
|
{team.name}
|
||||||
|
</strong>
|
||||||
|
</p>
|
||||||
|
{team.members.length > 0 && (
|
||||||
|
<div className="mt-1.5 flex min-w-0 items-center gap-2.5">
|
||||||
|
<span className="flex shrink-0 -space-x-1.5">
|
||||||
|
{team.members.map((member) => (
|
||||||
|
<img
|
||||||
|
key={member.userId}
|
||||||
|
src={profileIconUrl(manifest, member.profileIconId ?? 0)}
|
||||||
|
alt=""
|
||||||
|
className="size-7 rounded-full bg-sunken-strong object-cover ring-2 ring-body"
|
||||||
|
loading="lazy"
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
{memberNames && (
|
||||||
|
<span className="truncate text-xs text-content-muted" title={memberNames}>
|
||||||
|
{memberNames}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function RecentMatchResultsSkeleton({ limit }: { limit: number }) {
|
function RecentMatchResultsSkeleton({ limit }: { limit: number }) {
|
||||||
return (
|
return (
|
||||||
<div className="divide-y divide-line border-y border-line" aria-hidden="true">
|
<div className="divide-y divide-line border-y border-line" aria-hidden="true">
|
||||||
{Array.from({ length: limit }, (_, index) => (
|
{Array.from({ length: limit }, (_, index) => (
|
||||||
<div
|
<div key={index} className={RECENT_RESULT_ROW_CLASS}>
|
||||||
key={index}
|
|
||||||
className="grid gap-2 px-2 py-3.5 md:grid-cols-2 md:items-center"
|
|
||||||
>
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Skeleton width={130} height={16} index={index} />
|
<Skeleton width={80} height={16} index={index} />
|
||||||
<Skeleton width={96} height={12} index={index} />
|
<Skeleton width={64} height={12} index={index} />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton width={140} height={16} index={index} />
|
||||||
|
<Skeleton width={200} height={28} index={index} />
|
||||||
</div>
|
</div>
|
||||||
<Skeleton width={120} height={14} index={index} className="md:justify-self-end" />
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user