경기 기록 가져오기 진행 바 · 취소: 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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user