From 741fce0adb367d81cc3d840de19c2e7986310537 Mon Sep 17 00:00:00 2001 From: dahyeon Date: Fri, 3 Jul 2026 02:18:58 -0700 Subject: [PATCH] Add mentor match dashboard section --- .../modules/analysis/analysis-read.service.ts | 11 +- apps/api/test/app.e2e-spec.ts | 3 +- apps/web/src/App.css | 132 +++++++++- apps/web/src/api/analysis.ts | 11 + apps/web/src/pages/DashboardPage.tsx | 248 +++++++++++++++++- packages/shared/src/dto/analysis.dto.ts | 2 +- 6 files changed, 396 insertions(+), 11 deletions(-) diff --git a/apps/api/src/modules/analysis/analysis-read.service.ts b/apps/api/src/modules/analysis/analysis-read.service.ts index adb1658..6c3a01d 100644 --- a/apps/api/src/modules/analysis/analysis-read.service.ts +++ b/apps/api/src/modules/analysis/analysis-read.service.ts @@ -135,8 +135,12 @@ export class AnalysisReadService { puuid: mentorMatchesResult.puuid, queueId: mentorMatchesResult.queueId, profileUpdatedAt: mentorMatchesResult.profileUpdatedAt.toISOString(), - matches: mentorMatchesResult.matches.map((match) => - this.toMentorMatchDto(match, mentorAccountsByPuuid.get(match.puuid)), + matches: mentorMatchesResult.matches.map((match, index) => + this.toMentorMatchDto( + match, + mentorAccountsByPuuid.get(match.puuid), + index, + ), ), }; } @@ -224,9 +228,10 @@ export class AnalysisReadService { private toMentorMatchDto( match: MentorMatch, account: MentorAccountRecord | undefined, + index: number, ): MentorMatchesDto['matches'][number] { return { - puuid: match.puuid, + mentorDisplayId: `mentor-${index + 1}`, riotId: account ? { gameName: account.gameName, diff --git a/apps/api/test/app.e2e-spec.ts b/apps/api/test/app.e2e-spec.ts index 0023a07..820a55f 100644 --- a/apps/api/test/app.e2e-spec.ts +++ b/apps/api/test/app.e2e-spec.ts @@ -494,7 +494,7 @@ describe('AppController (e2e)', () => { profileUpdatedAt: '2026-07-02T00:00:00.000Z', matches: [ { - puuid: 'mentor-puuid', + mentorDisplayId: 'mentor-1', riotId: { gameName: '프리리', tagLine: 'KR1', @@ -525,6 +525,7 @@ describe('AppController (e2e)', () => { }, ], }); + expect(responseBody.matches[0]).not.toHaveProperty('puuid'); }); afterEach(async () => { diff --git a/apps/web/src/App.css b/apps/web/src/App.css index 560ac2a..15f7a95 100644 --- a/apps/web/src/App.css +++ b/apps/web/src/App.css @@ -107,6 +107,7 @@ .chart-section, .champion-section, .insight-section, +.mentor-section, .dashboard-summary { border: 1px solid var(--border); border-radius: 8px; @@ -342,7 +343,8 @@ .chart-section, .champion-section, -.insight-section { +.insight-section, +.mentor-section { padding: 24px; } @@ -435,6 +437,133 @@ white-space: nowrap; } +.section-copy { + margin: 8px 0 0; + color: var(--text-muted); + font-size: 14px; + line-height: 1.55; +} + +.mentor-message { + margin-top: 16px; +} + +.mentor-table-wrap { + margin-top: 18px; + overflow-x: auto; +} + +.mentor-table-wrap:focus-visible { + outline: 3px solid color-mix(in srgb, var(--accent) 42%, transparent); + outline-offset: 3px; +} + +.mentor-table { + width: 100%; + min-width: 780px; + border-collapse: separate; + border-spacing: 0 10px; +} + +.mentor-table th { + padding: 0 12px; + color: var(--text-subtle); + font-size: 12px; + font-weight: 800; + line-height: 1.3; + text-align: left; + text-transform: uppercase; +} + +.mentor-table td { + min-width: 0; + padding: 14px 12px; + border-block: 1px solid var(--border); + background: var(--surface-soft); + vertical-align: top; +} + +.mentor-table td:first-child { + border-left: 1px solid var(--border); + border-radius: 8px 0 0 8px; +} + +.mentor-table td:last-child { + border-right: 1px solid var(--border); + border-radius: 0 8px 8px 0; +} + +.mentor-player, +.mentor-score, +.mentor-metric-groups, +.mentor-metric-group { + min-width: 0; + display: grid; + gap: 6px; +} + +.mentor-player strong, +.mentor-score strong, +.mentor-chip strong { + overflow: hidden; + color: var(--text-strong); + text-overflow: ellipsis; + white-space: nowrap; +} + +.mentor-player span, +.mentor-score span, +.mentor-chip span, +.mentor-metric-group > span, +.mentor-empty { + color: var(--text-subtle); + font-size: 12px; + font-weight: 700; + line-height: 1.35; +} + +.mentor-score strong { + font-size: 22px; + line-height: 1; +} + +.mentor-chip-list { + display: flex; + flex-wrap: wrap; + gap: 6px; + margin: 0; + padding: 0; + list-style: none; +} + +.mentor-chip { + max-width: 100%; + display: inline-flex; + align-items: center; + gap: 6px; + border: 1px solid var(--border); + border-radius: 999px; + background: var(--surface); + padding: 5px 8px; +} + +.mentor-chip strong { + min-width: 0; +} + +.mentor-chip span { + flex: 0 0 auto; + white-space: nowrap; +} + +.mentor-chip-accent { + border-color: color-mix(in srgb, var(--accent) 48%, var(--border)); +} + +.mentor-chip-muted { + background: color-mix(in srgb, var(--surface) 74%, var(--surface-soft)); +} + .empty-view { min-height: calc(100svh - 240px); display: grid; @@ -535,6 +664,7 @@ .chart-section, .champion-section, .insight-section, + .mentor-section, .dashboard-summary { padding: 18px; } diff --git a/apps/web/src/api/analysis.ts b/apps/web/src/api/analysis.ts index cc579ad..a25dbf8 100644 --- a/apps/web/src/api/analysis.ts +++ b/apps/web/src/api/analysis.ts @@ -2,6 +2,7 @@ import type { AnalysisJobStatusDto, AnalysisRequestAcceptedDto, AnalysisRequestDto, + MentorMatchesDto, PlayerAnalysisDto, } from '@persona-lenz/shared'; @@ -97,3 +98,13 @@ export async function getLatestPlayerAnalysis( `/api/players/${encodeURIComponent(puuid)}/analysis/latest`, ); } + +export async function getMentorMatches( + puuid: string, + limit = 10, +): Promise { + const params = new URLSearchParams({ limit: String(limit) }); + return fetchJson( + `/api/players/${encodeURIComponent(puuid)}/mentor-matches?${params}`, + ); +} diff --git a/apps/web/src/pages/DashboardPage.tsx b/apps/web/src/pages/DashboardPage.tsx index be9a439..79cbf55 100644 --- a/apps/web/src/pages/DashboardPage.tsx +++ b/apps/web/src/pages/DashboardPage.tsx @@ -3,9 +3,13 @@ import { Link, useParams } from 'react-router-dom'; import { METRICS, type ChampionPoolEntryDto, + type GapMentorMetricDto, + type MentorMatchDto, + type MentorMatchesDto, type MetricId, type MetricValueDto, type PlayerAnalysisDto, + type SimilarMentorMetricDto, type TierInfoDto, } from '@persona-lenz/shared'; import { @@ -19,6 +23,7 @@ import { } from 'recharts'; import { getLatestPlayerAnalysis, + getMentorMatches, getReadableErrorMessage, } from '../api/analysis'; import { @@ -38,12 +43,19 @@ interface RadarMetricDatum { value: number; } +const MENTOR_MATCH_LIMIT = 10; + export function DashboardPage() { const { puuid } = useParams<{ puuid: string }>(); const [analysis, setAnalysis] = useState(null); const [championCatalog, setChampionCatalog] = useState(null); + const [mentorMatches, setMentorMatches] = + useState(null); const [errorMessage, setErrorMessage] = useState(null); + const [mentorErrorMessage, setMentorErrorMessage] = useState( + null, + ); const [isLoading, setIsLoading] = useState(true); const missingPuuidMessage = puuid ? null : '플레이어 식별자가 없습니다.'; @@ -57,22 +69,52 @@ export function DashboardPage() { async function loadDashboard() { setIsLoading(true); + setAnalysis(null); setErrorMessage(null); + setMentorErrorMessage(null); + setMentorMatches(null); + + const mentorMatchesResultPromise = getMentorMatches( + currentPuuid, + MENTOR_MATCH_LIMIT, + ).then( + (value) => ({ status: 'fulfilled', value }) as const, + (reason: unknown) => ({ status: 'rejected', reason }) as const, + ); try { const nextAnalysis = await getLatestPlayerAnalysis(currentPuuid); - if (isActive) { - setAnalysis(nextAnalysis); + if (!isActive) { + return; } + + setAnalysis(nextAnalysis); } catch (error) { if (isActive) { + setAnalysis(null); setErrorMessage(getReadableErrorMessage(error)); - } - } finally { - if (isActive) { setIsLoading(false); } + return; + } + + if (isActive) { + setIsLoading(false); + } + + const mentorMatchesResult = await mentorMatchesResultPromise; + + if (!isActive) { + return; + } + + if (mentorMatchesResult.status === 'fulfilled') { + setMentorMatches(mentorMatchesResult.value); + } else { + setMentorErrorMessage( + getReadableErrorMessage(mentorMatchesResult.reason), + ); } } @@ -236,6 +278,12 @@ export function DashboardPage() {

분석 가능한 챔피언 기록이 없습니다.

)} + + ); } @@ -310,6 +358,196 @@ function ChampionPoolRow({ ); } +function MentorMatchSection({ + catalog, + errorMessage, + mentorMatches, +}: { + catalog: ChampionCatalog | null; + errorMessage: string | null; + mentorMatches: MentorMatchesDto | null; +}) { + const matches = mentorMatches?.matches ?? []; + + return ( +
+
+
+

유사 상위 티어 비교

+

+ 당신과 비슷한 상위 티어 그룹은 이런 경향을 보입니다. +

+
+ + {mentorMatches ? `${matches.length} matches` : 'mentor match'} + +
+ + {errorMessage ? ( +

+ 멘토 비교를 불러오지 못했습니다. {errorMessage} +

+ ) : null} + + {!errorMessage && mentorMatches && matches.length === 0 ? ( +

+ 조건에 맞는 상위 티어 seed 프로필이 아직 없습니다. +

+ ) : null} + + {!errorMessage && !mentorMatches ? ( +

멘토 비교 결과를 준비 중입니다.

+ ) : null} + + {matches.length > 0 ? ( +
+ + + + + + + + + + + {matches.map((match) => ( + + + + + + + ))} + +
플레이어점수주요 챔피언비교 지표
+
+ {formatMentorName(match)} + + {formatMentorTier(match)} · {ROLE_LABELS[match.mainRole]} ·{' '} + {match.sampleGameCount}게임 + +
+
+
+ {formatPercent(match.finalScore)} + 스타일 {formatPercent(match.similarityScore)} +
+
+ + +
+ + +
+
+
+ ) : null} +
+ ); +} + +function MentorChampionList({ + catalog, + match, +}: { + catalog: ChampionCatalog | null; + match: MentorMatchDto; +}) { + if (match.mainChampions.length === 0) { + return 챔피언 기록 없음; + } + + return ( +
    + {match.mainChampions.map((entry) => ( +
  • + {formatChampionName(catalog, entry.championId)} + {entry.games}게임 +
  • + ))} +
+ ); +} + +function GapMetricChips({ values }: { values: GapMentorMetricDto[] }) { + if (values.length === 0) { + return 뚜렷한 우위 지표 없음; + } + + return ( +
+ 앞서는 지표 +
    + {values.map((value) => ( +
  • + {getMetricLabel(value.metricId)} + +{formatPercent(value.mentorAdvantage)} +
  • + ))} +
+
+ ); +} + +function SimilarMetricChips({ values }: { values: SimilarMentorMetricDto[] }) { + if (values.length === 0) { + return null; + } + + return ( +
+ 비슷한 지표 +
    + {values.map((value) => ( +
  • + {getMetricLabel(value.metricId)} + 차이 {formatPercent(value.absoluteGap)} +
  • + ))} +
+
+ ); +} + +function formatMentorName(match: MentorMatchDto): string { + if (match.riotId) { + return `${match.riotId.gameName}#${match.riotId.tagLine}`; + } + + return formatMentorDisplayId(match.mentorDisplayId); +} + +function formatMentorDisplayId(mentorDisplayId: string): string { + const numericSuffix = mentorDisplayId.match(/^mentor-(\d+)$/)?.[1]; + + return numericSuffix ? `상위 티어 멘토 #${numericSuffix}` : '상위 티어 멘토'; +} + +function formatMentorTier(match: MentorMatchDto): string { + const tier = [match.tier, match.division].filter(Boolean).join(' '); + + if (!tier) { + return '랭크 정보 없음'; + } + + return typeof match.leaguePoints === 'number' + ? `${tier} ${match.leaguePoints}LP` + : tier; +} + +function formatChampionName( + catalog: ChampionCatalog | null, + championId: number, +): string { + return catalog?.champions[championId]?.name ?? `챔피언 ${championId}`; +} + function pickSoloTier(tiers: TierInfoDto[]): TierInfoDto | null { return tiers.find((tier) => tier.queueType === 'RANKED_SOLO_5x5') ?? tiers[0] ?? null; } diff --git a/packages/shared/src/dto/analysis.dto.ts b/packages/shared/src/dto/analysis.dto.ts index 3e46ff2..22383b2 100644 --- a/packages/shared/src/dto/analysis.dto.ts +++ b/packages/shared/src/dto/analysis.dto.ts @@ -117,7 +117,7 @@ export interface GapMentorMetricDto { } export interface MentorMatchDto { - puuid: string; + mentorDisplayId: string; riotId: MentorRiotIdDto | null; similarityScore: number; finalScore: number;