경기 탭: 내가 플레이한 경기 전부 (Riot 경기 기록 포함) · 필터 (전체 경기 / 타임라인 있는 경기 / 목소리 녹음된 경기) · 지난 경기 더 보기 · 카드에 녹음 / 경기 기록만 표시 · 타임라인 사이드바는 타임라인 있는 경기만 · 목 서버에 기록 경기 70개
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -580,6 +580,34 @@ function genReplayDemo(file) {
|
||||
}
|
||||
if (process.env.GVR_MOCK_REPLAY) genReplayDemo(process.env.GVR_MOCK_REPLAY);
|
||||
|
||||
// Riot 경기 기록에서 가져온 경기 (v1.9.0, 겜녹이가 꺼져 있을 때 한 경기): 녹음 · 타임라인 없음
|
||||
{
|
||||
const base = matches.find((m) => m.game === 'valorant');
|
||||
const MAPS = ['어센트', '바인드', '헤이븐', '로터스', '선셋'];
|
||||
for (let i = 0; i < 70; i++) {
|
||||
const start = NOW - (1 + i * 0.37) * 24 * 60 * MIN;
|
||||
const ally = 13;
|
||||
const enemy = (i * 5) % 12;
|
||||
const win = i % 3 !== 0;
|
||||
matches.push({
|
||||
...base,
|
||||
id: `val-hist-${i}`,
|
||||
startedAt: start,
|
||||
endedAt: start + 38 * MIN,
|
||||
map: { ...base.map, name: MAPS[i % MAPS.length] },
|
||||
mode: i % 4 === 0 ? '일반전' : '경쟁전',
|
||||
win,
|
||||
score: win ? { ally, enemy } : { ally: enemy, enemy: ally },
|
||||
status: 'complete',
|
||||
participants: [],
|
||||
source: 'history',
|
||||
utterances: [],
|
||||
events: [],
|
||||
replayPath: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ── 내보내기 ─────────────────────────────────────────
|
||||
export const db = {
|
||||
users: USERS,
|
||||
|
||||
@@ -115,7 +115,10 @@ function timeline(q) {
|
||||
return { items: page, next: items.length > limit ? enc(page[page.length - 1]) : null };
|
||||
}
|
||||
|
||||
const summary = (m) => ({ id: m.id, game: m.game, startedAt: m.startedAt, endedAt: m.endedAt, map: m.map, mode: m.mode, win: m.win, score: m.score, status: m.status, participants: m.participants });
|
||||
const summary = (m) => ({
|
||||
id: m.id, game: m.game, startedAt: m.startedAt, endedAt: m.endedAt, map: m.map, mode: m.mode, win: m.win, score: m.score, status: m.status, participants: m.participants,
|
||||
source: m.source ?? 'live', voice: m.utterances.length > 0,
|
||||
});
|
||||
|
||||
function userProfile(id) {
|
||||
const user = db.users.find((u) => u.id === id);
|
||||
@@ -335,7 +338,9 @@ async function handle(req, res) {
|
||||
const game = q.get('game');
|
||||
const before = q.get('before') ? Number(q.get('before')) : Infinity;
|
||||
const limit = Number(q.get('limit') ?? 20);
|
||||
const list = db.matches.filter((x) => (!game || x.game === game) && x.startedAt < before).sort((a, b) => b.startedAt - a.startedAt).slice(0, limit).map(summary);
|
||||
const has = q.get('has');
|
||||
const keep = (x) => (has === 'voice' ? x.utterances.length > 0 : has === 'timeline' ? x.source !== 'history' || x.utterances.length > 0 : true);
|
||||
const list = db.matches.filter((x) => (!game || x.game === game) && x.startedAt < before && keep(x)).sort((a, b) => b.startedAt - a.startedAt).slice(0, limit).map(summary);
|
||||
return json(res, 200, list);
|
||||
}
|
||||
if ((m = p.match(/^\/api\/matches\/([^/]+)$/))) {
|
||||
|
||||
@@ -42,6 +42,9 @@ export class ApiError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
/** 경기 탭 필터 */
|
||||
export type MatchHas = 'timeline' | 'voice';
|
||||
|
||||
async function request<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
let res: Response;
|
||||
try {
|
||||
@@ -162,7 +165,8 @@ export const api = {
|
||||
hideNoise: 1,
|
||||
})}`,
|
||||
),
|
||||
matches: (o: { game?: GameType; limit?: number; before?: number } = {}) => request<MatchSummary[]>(`/api/matches${qs(o)}`),
|
||||
// has: timeline = 타임라인에 나오는 경기, voice = 목소리가 녹음된 경기 (v1.9.0 앱부터, 예전 앱은 무시하고 다 보냄)
|
||||
matches: (o: { game?: GameType; limit?: number; before?: number; has?: MatchHas } = {}) => request<MatchSummary[]>(`/api/matches${qs(o)}`),
|
||||
match: (id: string) => request<MatchDetail>(`/api/matches/${encodeURIComponent(id)}`),
|
||||
/** 발로란트 리플레이(.vrf)에서 뽑은 재생 데이터. 없으면 404 replay_not_found, 게임 PC 가 변환 중이면 202 { status: 'converting' } */
|
||||
// fresh: 새로고침 때는 브라우저 캐시를 거치지 않는다 (방금 내려받은 리플레이가 보이게)
|
||||
|
||||
@@ -15,7 +15,9 @@ export function toggleUser(f: Filters, users: User[], id: string): string[] {
|
||||
return all.every((x) => nextSet.includes(x)) ? [] : nextSet;
|
||||
}
|
||||
|
||||
export function MatchItem({ m, on, onClick }: { m: MatchSummary; on?: boolean; onClick?: () => void }) {
|
||||
/** tags: 경기 탭에서 녹음 · 기록만 표시 */
|
||||
export function MatchItem({ m, on, onClick, tags }: { m: MatchSummary; on?: boolean; onClick?: () => void; tags?: boolean }) {
|
||||
const voice = m.voice ?? m.participants.length > 0;
|
||||
const dur = m.endedAt ? Math.round((m.endedAt - m.startedAt) / 60000) : null;
|
||||
const res = m.win == null ? '' : m.win ? '승' : '패';
|
||||
const Tag = onClick ? 'button' : 'div';
|
||||
@@ -32,6 +34,19 @@ export function MatchItem({ m, on, onClick }: { m: MatchSummary; on?: boolean; o
|
||||
{dur != null ? ` · ${dur}분` : ''}
|
||||
{m.status === 'live' && <span className="live-dot"> · 진행 중</span>}
|
||||
</div>
|
||||
{tags && (voice || m.source === 'history') && (
|
||||
<div className="m-tags">
|
||||
{voice ? (
|
||||
<span className="m-tag voice" title="디스코드 대화가 녹음된 경기">
|
||||
🎙 녹음
|
||||
</span>
|
||||
) : (
|
||||
<span className="m-tag hist" title="겜녹이가 꺼져 있을 때 한 경기 (Riot 경기 기록에서 가져옴)">
|
||||
경기 기록만
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{res && <span className={`badge ${m.win ? 'b-win' : 'b-loss'}`}>{res}</span>}
|
||||
</Tag>
|
||||
|
||||
@@ -257,7 +257,7 @@ export function TimelinePage() {
|
||||
// 사이드바 경기 목록 · 선택한 경기 상세
|
||||
useEffect(() => {
|
||||
api
|
||||
.matches({ limit: 15, game: f.game === 'valorant' || f.game === 'lol' ? f.game : undefined })
|
||||
.matches({ limit: 15, game: f.game === 'valorant' || f.game === 'lol' ? f.game : undefined, has: 'timeline' })
|
||||
.then(setMatches)
|
||||
.catch(() => {});
|
||||
}, [f.game, epoch]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { Link, useNavigate, useParams } from 'react-router';
|
||||
import type { GameType, MatchSummary, User, UserProfile } from '@gvr/shared';
|
||||
import { api } from '../lib/api';
|
||||
import { api, type MatchHas } from '../lib/api';
|
||||
import { useStatus } from '../store/app';
|
||||
import { fmtDuration, fmtDay } from '../lib/format';
|
||||
import { sfx } from '../lib/sfx';
|
||||
@@ -50,18 +50,53 @@ export function UsersPage() {
|
||||
);
|
||||
}
|
||||
|
||||
const PAGE = 50;
|
||||
/** 목소리가 녹음된 경기 (예전 앱은 voice 가 없어 말한 사람으로 본다) */
|
||||
const hasVoice = (m: MatchSummary) => m.voice ?? m.participants.length > 0;
|
||||
const HAS_CHIPS: { has: MatchHas | null; label: string; title: string }[] = [
|
||||
{ has: null, label: '전체 경기', title: '내가 플레이한 경기 전부 (앱이 꺼져 있을 때 한 경기는 Riot 경기 기록에서 가져옴)' },
|
||||
{ has: 'timeline', label: '타임라인 있는 경기', title: '겜녹이가 켜져 있을 때 한 경기 (타임라인에서 대화 · 킬을 같이 볼 수 있음)' },
|
||||
{ has: 'voice', label: '목소리 녹음된 경기', title: '디스코드 대화가 녹음된 경기' },
|
||||
];
|
||||
|
||||
export function MatchesPage() {
|
||||
const [game, setGame] = useState<GameType | null>(null);
|
||||
const [has, setHas] = useState<MatchHas | null>(null);
|
||||
const nav = useNavigate();
|
||||
const { data, err, retry } = useLoad<MatchSummary[]>(() => api.matches({ limit: 50, game: game ?? undefined }), [game]);
|
||||
const { data, err, retry } = useLoad<MatchSummary[]>(() => api.matches({ limit: PAGE, game: game ?? undefined, has: has ?? undefined }), [game, has]);
|
||||
// 더 보기: 지난 쪽 경기들 (필터가 바뀌면 처음부터)
|
||||
const [more, setMore] = useState<{ list: MatchSummary[]; done: boolean; busy: boolean; err: unknown }>({ list: [], done: false, busy: false, err: null });
|
||||
useEffect(() => setMore({ list: [], done: false, busy: false, err: null }), [data]);
|
||||
const all = useMemo(() => {
|
||||
const seen = new Set<string>();
|
||||
const out: MatchSummary[] = [];
|
||||
for (const m of [...(data ?? []), ...more.list]) {
|
||||
if (seen.has(m.id)) continue;
|
||||
seen.add(m.id);
|
||||
// 예전 앱은 has 를 모르고 다 보낸다: 목소리 필터는 여기서도 거른다
|
||||
if (has === 'voice' && !hasVoice(m)) continue;
|
||||
out.push(m);
|
||||
}
|
||||
return out;
|
||||
}, [data, more.list, has]);
|
||||
const canMore = !!data && data.length >= PAGE && !more.done;
|
||||
const loadMore = () => {
|
||||
const last = more.list[more.list.length - 1] ?? data?.[data.length - 1];
|
||||
if (!last || more.busy) return;
|
||||
setMore((s) => ({ ...s, busy: true, err: null }));
|
||||
api
|
||||
.matches({ limit: PAGE, game: game ?? undefined, has: has ?? undefined, before: last.startedAt })
|
||||
.then((r) => setMore((s) => ({ list: [...s.list, ...r], done: r.length < PAGE, busy: false, err: null })))
|
||||
.catch((e) => setMore((s) => ({ ...s, busy: false, err: e })));
|
||||
};
|
||||
const groups = useMemo(() => {
|
||||
const g = new Map<string, MatchSummary[]>();
|
||||
for (const m of data ?? []) {
|
||||
for (const m of all) {
|
||||
const d = fmtDay(m.startedAt);
|
||||
g.set(d, [...(g.get(d) ?? []), m]);
|
||||
}
|
||||
return [...g];
|
||||
}, [data]);
|
||||
}, [all]);
|
||||
return (
|
||||
<main className="page-pad">
|
||||
<div className="page-h-row">
|
||||
@@ -78,19 +113,38 @@ export function MatchesPage() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="chips-wrap match-has">
|
||||
{HAS_CHIPS.map((c) => (
|
||||
<button key={c.label} className={`chip${has === c.has ? ' on-mint' : ''}`} title={c.title} onClick={() => setHas(c.has)}>
|
||||
{c.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{err != null && <ErrorBox error={err} onRetry={retry} />}
|
||||
{!data && !err && <Spinner />}
|
||||
{data && data.length === 0 && <div className="empty">경기 기록이 없습니다.</div>}
|
||||
{data && all.length === 0 && (
|
||||
<div className="empty">
|
||||
{has === 'voice' ? '목소리가 녹음된 경기가 없습니다.' : has === 'timeline' ? '타임라인이 있는 경기가 없습니다.' : '경기 기록이 없습니다.'}
|
||||
</div>
|
||||
)}
|
||||
{groups.map(([day, ms]) => (
|
||||
<section key={day} className="match-day">
|
||||
<h4>{day}</h4>
|
||||
<div className="match-cards">
|
||||
{ms.map((m) => (
|
||||
<MatchItem key={m.id} m={m} onClick={() => nav(`/matches/${encodeURIComponent(m.id)}`)} />
|
||||
<MatchItem key={m.id} m={m} tags onClick={() => nav(`/matches/${encodeURIComponent(m.id)}`)} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
))}
|
||||
{more.err != null && <ErrorBox error={more.err} onRetry={loadMore} />}
|
||||
{canMore && (
|
||||
<div className="more-row">
|
||||
<button className="btn" onClick={loadMore} disabled={more.busy}>
|
||||
{more.busy ? '불러오는 중…' : '지난 경기 더 보기'}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2737,6 +2737,33 @@ button.match:hover {
|
||||
letter-spacing: 1px;
|
||||
margin: 20px 0 8px;
|
||||
}
|
||||
.match-has {
|
||||
margin: 4px 0 2px;
|
||||
}
|
||||
.m-tags {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
.m-tag {
|
||||
font-size: 11px;
|
||||
padding: 0 6px;
|
||||
border-radius: 4px;
|
||||
line-height: 17px;
|
||||
}
|
||||
.m-tag.voice {
|
||||
background: #0f2e2c;
|
||||
color: #7fe9e1;
|
||||
}
|
||||
.m-tag.hist {
|
||||
background: #1a2633;
|
||||
color: var(--muted);
|
||||
}
|
||||
.more-row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 18px 0 8px;
|
||||
}
|
||||
.match-cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
|
||||
Reference in New Issue
Block a user