Add mentor match dashboard section
This commit is contained in:
1 parent
1d8037adf1
commit
741fce0adb
6 files changed
+396
-11
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
+131
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<MentorMatchesDto> {
|
||||
const params = new URLSearchParams({ limit: String(limit) });
|
||||
return fetchJson<MentorMatchesDto>(
|
||||
`/api/players/${encodeURIComponent(puuid)}/mentor-matches?${params}`,
|
||||
);
|
||||
}
|
||||
@@ -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<PlayerAnalysisDto | null>(null);
|
||||
const [championCatalog, setChampionCatalog] =
|
||||
useState<ChampionCatalog | null>(null);
|
||||
const [mentorMatches, setMentorMatches] =
|
||||
useState<MentorMatchesDto | null>(null);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [mentorErrorMessage, setMentorErrorMessage] = useState<string | null>(
|
||||
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() {
|
||||
<p className="empty-copy">분석 가능한 챔피언 기록이 없습니다.</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<MentorMatchSection
|
||||
catalog={championCatalog}
|
||||
errorMessage={mentorErrorMessage}
|
||||
mentorMatches={mentorMatches}
|
||||
/>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<section className="mentor-section" aria-labelledby="mentor-title">
|
||||
<div className="section-heading">
|
||||
<div>
|
||||
<h2 id="mentor-title">유사 상위 티어 비교</h2>
|
||||
<p className="section-copy">
|
||||
당신과 비슷한 상위 티어 그룹은 이런 경향을 보입니다.
|
||||
</p>
|
||||
</div>
|
||||
<span className="status-pill">
|
||||
{mentorMatches ? `${matches.length} matches` : 'mentor match'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{errorMessage ? (
|
||||
<p className="message message-warning mentor-message" role="status">
|
||||
멘토 비교를 불러오지 못했습니다. {errorMessage}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{!errorMessage && mentorMatches && matches.length === 0 ? (
|
||||
<p className="empty-copy">
|
||||
조건에 맞는 상위 티어 seed 프로필이 아직 없습니다.
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{!errorMessage && !mentorMatches ? (
|
||||
<p className="empty-copy">멘토 비교 결과를 준비 중입니다.</p>
|
||||
) : null}
|
||||
|
||||
{matches.length > 0 ? (
|
||||
<div
|
||||
aria-label="유사 상위 티어 비교 테이블"
|
||||
className="mentor-table-wrap"
|
||||
role="region"
|
||||
tabIndex={0}
|
||||
>
|
||||
<table className="mentor-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">플레이어</th>
|
||||
<th scope="col">점수</th>
|
||||
<th scope="col">주요 챔피언</th>
|
||||
<th scope="col">비교 지표</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{matches.map((match) => (
|
||||
<tr key={match.mentorDisplayId}>
|
||||
<td>
|
||||
<div className="mentor-player">
|
||||
<strong>{formatMentorName(match)}</strong>
|
||||
<span>
|
||||
{formatMentorTier(match)} · {ROLE_LABELS[match.mainRole]} ·{' '}
|
||||
{match.sampleGameCount}게임
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div className="mentor-score">
|
||||
<strong>{formatPercent(match.finalScore)}</strong>
|
||||
<span>스타일 {formatPercent(match.similarityScore)}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<MentorChampionList catalog={catalog} match={match} />
|
||||
</td>
|
||||
<td>
|
||||
<div className="mentor-metric-groups">
|
||||
<GapMetricChips values={match.gapMetrics} />
|
||||
<SimilarMetricChips values={match.similarMetrics} />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function MentorChampionList({
|
||||
catalog,
|
||||
match,
|
||||
}: {
|
||||
catalog: ChampionCatalog | null;
|
||||
match: MentorMatchDto;
|
||||
}) {
|
||||
if (match.mainChampions.length === 0) {
|
||||
return <span className="mentor-empty">챔피언 기록 없음</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className="mentor-chip-list">
|
||||
{match.mainChampions.map((entry) => (
|
||||
<li className="mentor-chip" key={entry.championId}>
|
||||
<strong>{formatChampionName(catalog, entry.championId)}</strong>
|
||||
<span>{entry.games}게임</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
function GapMetricChips({ values }: { values: GapMentorMetricDto[] }) {
|
||||
if (values.length === 0) {
|
||||
return <span className="mentor-empty">뚜렷한 우위 지표 없음</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mentor-metric-group">
|
||||
<span>앞서는 지표</span>
|
||||
<ul className="mentor-chip-list">
|
||||
{values.map((value) => (
|
||||
<li className="mentor-chip mentor-chip-accent" key={value.metricId}>
|
||||
<strong>{getMetricLabel(value.metricId)}</strong>
|
||||
<span>+{formatPercent(value.mentorAdvantage)}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SimilarMetricChips({ values }: { values: SimilarMentorMetricDto[] }) {
|
||||
if (values.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mentor-metric-group">
|
||||
<span>비슷한 지표</span>
|
||||
<ul className="mentor-chip-list">
|
||||
{values.map((value) => (
|
||||
<li className="mentor-chip mentor-chip-muted" key={value.metricId}>
|
||||
<strong>{getMetricLabel(value.metricId)}</strong>
|
||||
<span>차이 {formatPercent(value.absoluteGap)}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user