경기 기록 가져오기 진행 바 · 취소: Riot 경기 기록을 가져오는 동안 사이트 경기 탭 · 앱 게임 연동 탭에 목록 확인 중(얼마나 걸릴지 모름) → 받은 경기 / 받을 경기 · % · 남은 시간 진행 바와 취소 버튼 (취소하면 받은 경기는 남고 다음 주기에 남은 것부터 이어서) · 진행 상황은 games.state 의 history 로 보냄 · POST /api/games/history/cancel · 끝나면 경기 목록 새로 · 목록 불러오는 중 표시 · schema.ts 사본 다시 맞춤
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
71
site/web/src/components/HistoryImport.tsx
Normal file
71
site/web/src/components/HistoryImport.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { GAME_NAME, historyStatus, resumeText, type GameType } from '@gvr/shared';
|
||||
import { api } from '../lib/api';
|
||||
import { useData } from '../store/app';
|
||||
|
||||
/**
|
||||
* Riot 경기 기록 가져오기 진행 바 (v1.9.1, 경기 탭 위). 게임 PC 앱이 게임 중이 아닐 때 30분마다 지난 경기를 받아 온다.
|
||||
* 받을 경기 수 · 남은 시간을 보여 주고 취소할 수 있다. 끝나면 onDone 으로 경기 목록을 다시 받게 한다.
|
||||
*/
|
||||
export function HistoryImport({ onDone }: { onDone: () => void }) {
|
||||
const { overview } = useData();
|
||||
const rows = (overview?.live ?? []).filter((g) => g.history);
|
||||
const [busy, setBusy] = useState<GameType | null>(null);
|
||||
const [msg, setMsg] = useState<{ text: string; bad?: boolean } | null>(null);
|
||||
// 가져오기가 끝나거나 멈추면 경기 목록을 새로
|
||||
const active = rows.map((g) => g.game).join(',');
|
||||
const prev = useRef(active);
|
||||
useEffect(() => {
|
||||
const now = active.split(',');
|
||||
if (prev.current.split(',').some((g) => g && !now.includes(g))) onDone();
|
||||
prev.current = active;
|
||||
}, [active, onDone]);
|
||||
const cancel = (game: GameType) => {
|
||||
setBusy(game);
|
||||
setMsg(null);
|
||||
api
|
||||
.cancelHistory(game)
|
||||
.then((r) => {
|
||||
if (r.cancelled.length) setMsg({ text: `${GAME_NAME[game]} 경기 기록 가져오기를 멈췄습니다. 받은 경기는 그대로 있고, ${resumeText(r.resumeAt)} 남은 것부터 이어서 가져옵니다.` });
|
||||
})
|
||||
.catch((e) => setMsg({ text: `취소하지 못했습니다: ${e instanceof Error ? e.message : String(e)}`, bad: true }))
|
||||
.finally(() => setBusy(null));
|
||||
};
|
||||
if (!rows.length && !msg) return null;
|
||||
return (
|
||||
<div className="hist-import">
|
||||
{rows.map((g) => {
|
||||
const st = historyStatus(g.history!);
|
||||
return (
|
||||
<div key={g.game} className={`hist-card ${g.game}`} role="status">
|
||||
<div className="hist-top">
|
||||
<span className="hist-dot" />
|
||||
<b>{GAME_NAME[g.game]}</b>
|
||||
<span>{st.title}</span>
|
||||
<span className="dim small">{st.detail}</span>
|
||||
<span className="hist-gap" />
|
||||
<button className="btn small" disabled={busy === g.game} onClick={() => cancel(g.game)}>
|
||||
{busy === g.game ? '멈추는 중…' : '취소'}
|
||||
</button>
|
||||
</div>
|
||||
<span className={`bar hist-bar${st.pct == null ? ' indet' : ''}`}>
|
||||
<i style={st.pct == null ? undefined : { width: `${st.pct}%` }} />
|
||||
</span>
|
||||
<div className="dim small">
|
||||
{g.history!.first ? '처음 한 번은 지난 경기를 끝까지 가져와서 오래 걸립니다. ' : ''}
|
||||
게임을 켜면 바로 멈추고, 끝나면 이 목록에 자동으로 나타납니다.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{msg && (
|
||||
<div className={`hist-msg${msg.bad ? ' bad' : ''}`}>
|
||||
{msg.text}
|
||||
<button className="btn small" onClick={() => setMsg(null)}>
|
||||
닫기
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -232,6 +232,9 @@ export const api = {
|
||||
/** 발화 지우기 (v1.4.0). noise = 잡음이라 삭제 (같은 문장을 다음부터 잡음으로) */
|
||||
deleteUtterance: (id: string, noise: boolean) =>
|
||||
request<{ ok: true; learned: string | null }>(`/api/utterances/${encodeURIComponent(id)}/delete`, { method: 'POST', body: JSON.stringify({ noise }) }),
|
||||
/** Riot 경기 기록 가져오기 취소 (v1.9.1). 받은 경기는 남고 resumeAt 에 이어서 한다 */
|
||||
cancelHistory: (game?: GameType) =>
|
||||
request<{ ok: true; cancelled: GameType[]; resumeAt: number | null }>('/api/games/history/cancel', { method: 'POST', body: JSON.stringify({ game }) }),
|
||||
noisePhrases: () => request<{ phrases: NoisePhrase[] }>('/api/noise-phrases'),
|
||||
deleteNoisePhrase: (id: number) => request<{ ok: true }>(`/api/noise-phrases/${id}`, { method: 'DELETE' }),
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ import { fmtDuration, fmtDay } from '../lib/format';
|
||||
import { sfx } from '../lib/sfx';
|
||||
import { Avatar, ErrorBox, Spinner } from '../components/common';
|
||||
import { MatchItem } from './Sidebar';
|
||||
import { HistoryImport } from '../components/HistoryImport';
|
||||
|
||||
function useLoad<T>(fn: () => Promise<T>, deps: unknown[]) {
|
||||
const { epoch } = useStatus();
|
||||
@@ -120,8 +121,9 @@ export function MatchesPage() {
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<HistoryImport onDone={retry} />
|
||||
{err != null && <ErrorBox error={err} onRetry={retry} />}
|
||||
{!data && !err && <Spinner />}
|
||||
{!data && !err && <Spinner label="경기 목록 불러오는 중" />}
|
||||
{data && all.length === 0 && (
|
||||
<div className="empty">
|
||||
{has === 'voice' ? '목소리가 녹음된 경기가 없습니다.' : has === 'timeline' ? '타임라인이 있는 경기가 없습니다.' : '경기 기록이 없습니다.'}
|
||||
|
||||
@@ -4528,3 +4528,83 @@ button.match:hover {
|
||||
max-height: calc(100vh - var(--header-h) - 16px);
|
||||
}
|
||||
}
|
||||
|
||||
/* Riot 경기 기록 가져오기 진행 바 (v1.9.1, 경기 탭) */
|
||||
.hist-import {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin: 10px 0 4px;
|
||||
}
|
||||
.hist-card {
|
||||
border: 1px solid var(--line);
|
||||
border-left: 3px solid var(--accent);
|
||||
border-radius: 10px;
|
||||
background: var(--panel);
|
||||
padding: 10px 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
}
|
||||
.hist-card.lol {
|
||||
border-left-color: var(--lol);
|
||||
}
|
||||
.hist-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.hist-gap {
|
||||
flex: 1;
|
||||
}
|
||||
.hist-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--mint);
|
||||
animation: hist-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
@keyframes hist-pulse {
|
||||
50% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
}
|
||||
.hist-card .btn,
|
||||
.hist-msg .btn {
|
||||
padding: 5px 12px;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.hist-bar i {
|
||||
background: var(--mint);
|
||||
}
|
||||
.hist-card.lol .hist-bar i {
|
||||
background: var(--lol);
|
||||
}
|
||||
.hist-bar.indet i {
|
||||
width: 35%;
|
||||
animation: hist-indet 1.4s ease-in-out infinite;
|
||||
}
|
||||
@keyframes hist-indet {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(290%);
|
||||
}
|
||||
}
|
||||
.hist-msg {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
font-size: 13px;
|
||||
padding: 8px 14px;
|
||||
border-radius: 10px;
|
||||
background: var(--panel2);
|
||||
color: var(--muted);
|
||||
}
|
||||
.hist-msg.bad {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user