경기 탭: 더 보기 요청 중 새로고침 · 필터 변경하면 늦게 온 더 보기 응답은 버림 (moreGen 세대)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Link, useNavigate, useParams } from 'react-router';
|
||||
import type { GameType, MatchSummary, User, UserProfile } from '@gvr/shared';
|
||||
import { api, type MatchHas } from '../lib/api';
|
||||
@@ -100,7 +100,12 @@ export function MatchesPage() {
|
||||
}, [game, data]);
|
||||
// 더 보기: 지난 쪽 경기들 (필터가 바뀌면 처음부터)
|
||||
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]);
|
||||
// 세대: 첫 쪽(data)이 바뀌면 올리고, 그 전에 보낸 더 보기 응답은 버린다 (새로고침 · 필터 변경 중 늦게 온 응답이 다시 펼치지 않게)
|
||||
const moreGen = useRef(0);
|
||||
useEffect(() => {
|
||||
moreGen.current++;
|
||||
setMore({ list: [], done: false, busy: false, err: null });
|
||||
}, [data]);
|
||||
const all = useMemo(() => {
|
||||
const seen = new Set<string>();
|
||||
const out: MatchSummary[] = [];
|
||||
@@ -124,11 +129,12 @@ export function MatchesPage() {
|
||||
const loadMore = () => {
|
||||
const last = more.list[more.list.length - 1] ?? data?.[data.length - 1];
|
||||
if (!last || more.busy) return;
|
||||
const gen = moreGen.current;
|
||||
setMore((s) => ({ ...s, busy: true, err: null }));
|
||||
api
|
||||
.matches({ ...query, 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 })));
|
||||
.then((r) => gen === moreGen.current && setMore((s) => ({ list: [...s.list, ...r], done: r.length < PAGE, busy: false, err: null })))
|
||||
.catch((e) => gen === moreGen.current && setMore((s) => ({ ...s, busy: false, err: e })));
|
||||
};
|
||||
const filtered = !!mode || from !== undefined || to !== undefined;
|
||||
const groups = useMemo(() => {
|
||||
|
||||
Reference in New Issue
Block a user