경기 탭 새로고침 버튼 (지금 필터로 첫 쪽부터 다시 받음 · 받는 동안 '불러오는 중…' 으로 잠금, useLoad loading)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-21 09:37:54 +09:00
parent ba45aa8792
commit 83cc9d1596

View File

@@ -14,18 +14,21 @@ function useLoad<T>(fn: () => Promise<T>, deps: unknown[]) {
const [data, setData] = useState<T | null>(null);
const [err, setErr] = useState<unknown>(null);
const [n, setN] = useState(0);
const [loading, setLoading] = useState(true);
useEffect(() => {
let alive = true;
setErr(null);
setLoading(true);
fn()
.then((d) => alive && setData(d))
.catch((e) => alive && setErr(e));
.catch((e) => alive && setErr(e))
.finally(() => alive && setLoading(false));
return () => {
alive = false;
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [...deps, epoch, n]);
return { data, err, retry: () => setN((x) => x + 1) };
return { data, err, loading, retry: () => setN((x) => x + 1) };
}
export function UsersPage() {
@@ -77,7 +80,7 @@ export function MatchesPage() {
};
const nav = useNavigate();
const query = { limit: PAGE, game: game ?? undefined, has: has ?? undefined, mode: mode ?? undefined, after: from, before: to === undefined ? undefined : to + 1 };
const { data, err, retry } = useLoad<MatchSummary[]>(() => api.matches(query), [game, has, mode, from, to]);
const { data, err, loading, retry } = useLoad<MatchSummary[]>(() => api.matches(query), [game, has, mode, from, to]);
// 모드 목록: 예전 앱(404)은 불러온 경기에서 만든다
const [modeList, setModeList] = useState<{ mode: string; count: number | null }[] | null>(null);
useEffect(() => {
@@ -141,6 +144,10 @@ export function MatchesPage() {
<div className="page-h-row">
<h2 className="page-h h">경기</h2>
<div className="chips-wrap">
{/* 새로고침: 지금 필터로 첫 쪽부터 다시 받는다 (모드 목록도 data 를 따라 다시 받음) */}
<button className="mini-btn" onClick={retry} disabled={loading} title="경기 목록 새로고침">
{loading ? '불러오는 중…' : '↻ 새로고침'}
</button>
<button className={`chip${!game ? ' on' : ''}`} onClick={() => setGame(null)}>
전체
</button>