경기 탭 리플레이 필터: 리플레이 있는 경기 / 없는 경기 (게임 PC 에 발로란트 .vrf 가 있는지, GET /api/matches?replay=yes|no · 롤 제외 · 요약에 replay) · 예전 앱이면 업데이트 안내 · 롤을 고르면 숨김 · '필터 초기화' · 목 서버 · 시험 · v1.12.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,7 @@ export class ApiError extends Error {
|
||||
|
||||
/** 경기 탭 필터 */
|
||||
export type MatchHas = 'timeline' | 'voice';
|
||||
export type MatchReplay = 'yes' | 'no';
|
||||
|
||||
async function request<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
let res: Response;
|
||||
@@ -167,7 +168,8 @@ export const api = {
|
||||
),
|
||||
// has: timeline = 타임라인에 나오는 경기, voice = 목소리가 녹음된 경기 (v1.9.0 앱부터, 예전 앱은 무시하고 다 보냄)
|
||||
// mode · after (v1.11.0 앱부터): 모드 이름("경쟁전") · 이 시각 이후 시작한 경기. 데스매치는 앱이 늘 뺀다 (예전 앱은 사이트가 거름)
|
||||
matches: (o: { game?: GameType; limit?: number; before?: number; after?: number; has?: MatchHas; mode?: string } = {}) =>
|
||||
// replay (v1.12.0 앱부터): yes = 게임 PC 에 리플레이 파일이 있는 발로란트 경기, no = 없는 발로란트 경기 (예전 앱은 무시하고 다 보냄)
|
||||
matches: (o: { game?: GameType; limit?: number; before?: number; after?: number; has?: MatchHas; mode?: string; replay?: MatchReplay } = {}) =>
|
||||
request<MatchSummary[]>(`/api/matches${qs(o)}`),
|
||||
/** 경기 탭 모드 필터 목록 (v1.11.0 앱부터, 예전 앱은 404) */
|
||||
matchModes: (game?: GameType) => request<{ game: GameType; mode: string; count: number }[]>(`/api/matches/modes${qs({ game })}`),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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';
|
||||
import { api, type MatchHas, type MatchReplay } from '../lib/api';
|
||||
import { useStatus } from '../store/app';
|
||||
import { dateInputToMs, dateInputValue, fmtDuration, fmtDay } from '../lib/format';
|
||||
import { sfx } from '../lib/sfx';
|
||||
@@ -70,17 +70,19 @@ export function MatchesPage() {
|
||||
const [game, setGameRaw] = useState<GameType | null>(null);
|
||||
const [has, setHas] = useState<MatchHas | null>(null);
|
||||
const [mode, setMode] = useState<string | null>(null);
|
||||
const [replay, setReplay] = useState<MatchReplay | null>(null);
|
||||
// 날짜 (한국 시각): from = 시작 날 0시, to = 끝 날 23:59:59.999
|
||||
const [from, setFrom] = useState<number | undefined>(undefined);
|
||||
const [to, setTo] = useState<number | undefined>(undefined);
|
||||
// 게임을 바꾸면 그 게임에 없을 수 있는 모드는 풀어 준다
|
||||
// 게임을 바꾸면 그 게임에 없을 수 있는 모드는 풀어 준다 (리플레이 필터는 발로란트만)
|
||||
const setGame = (g: GameType | null) => {
|
||||
setGameRaw(g);
|
||||
setMode(null);
|
||||
if (g === 'lol') setReplay(null);
|
||||
};
|
||||
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, loading, retry } = useLoad<MatchSummary[]>(() => api.matches(query), [game, has, mode, from, to]);
|
||||
const query = { limit: PAGE, game: game ?? undefined, has: has ?? undefined, mode: mode ?? undefined, replay: replay ?? undefined, after: from, before: to === undefined ? undefined : to + 1 };
|
||||
const { data, err, loading, retry } = useLoad<MatchSummary[]>(() => api.matches(query), [game, has, mode, replay, from, to]);
|
||||
// 모드 목록: 예전 앱(404)은 불러온 경기에서 만든다
|
||||
const [modeList, setModeList] = useState<{ mode: string; count: number | null }[] | null>(null);
|
||||
useEffect(() => {
|
||||
@@ -115,11 +117,13 @@ export function MatchesPage() {
|
||||
// 예전 앱은 has · 모드 · 날짜를 모르고 다 보낸다: 여기서도 거른다
|
||||
if (has === 'voice' && !hasVoice(m)) continue;
|
||||
if (m.mode === HIDDEN_MODE || (mode && m.mode !== mode)) continue;
|
||||
// 리플레이를 모르는(replay 없음) 예전 앱 경기는 리플레이 필터에서 뺀다
|
||||
if (replay && (m.game !== 'valorant' || m.replay !== (replay === 'yes'))) continue;
|
||||
if ((from !== undefined && m.startedAt < from) || (to !== undefined && m.startedAt > to)) continue;
|
||||
out.push(m);
|
||||
}
|
||||
return out;
|
||||
}, [data, more.list, has, mode, from, to]);
|
||||
}, [data, more.list, has, mode, replay, from, to]);
|
||||
const modes = useMemo(() => {
|
||||
if (modeList) return modeList;
|
||||
const seen = [...new Set([...(data ?? []), ...more.list].filter((m) => !game || m.game === game).map((m) => m.mode))];
|
||||
@@ -136,7 +140,9 @@ export function MatchesPage() {
|
||||
.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 filtered = !!mode || !!replay || from !== undefined || to !== undefined;
|
||||
// 예전 앱(v1.11 이하)은 리플레이를 몰라 리플레이 필터가 되지 않는다
|
||||
const replayUnknown = !!replay && !!data?.length && data.every((m) => m.replay === undefined);
|
||||
const groups = useMemo(() => {
|
||||
const g = new Map<string, MatchSummary[]>();
|
||||
for (const m of all) {
|
||||
@@ -183,6 +189,13 @@ export function MatchesPage() {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{game !== 'lol' && (
|
||||
<select className="mf-sel" value={replay ?? ''} onChange={(e) => setReplay((e.target.value || null) as MatchReplay | null)} aria-label="리플레이" title="게임 PC 에 발로란트 리플레이 파일을 내려받았는지">
|
||||
<option value="">리플레이 상관없음</option>
|
||||
<option value="yes">리플레이 있는 경기</option>
|
||||
<option value="no">리플레이 없는 경기</option>
|
||||
</select>
|
||||
)}
|
||||
<div className="dates mf-dates">
|
||||
<input type="date" value={dateInputValue(from)} max={dateInputValue(to)} onChange={(e) => setFrom(dateInputToMs(e.target.value))} aria-label="시작 날짜" />
|
||||
<span className="dim">~</span>
|
||||
@@ -193,11 +206,12 @@ export function MatchesPage() {
|
||||
className="link-btn"
|
||||
onClick={() => {
|
||||
setMode(null);
|
||||
setReplay(null);
|
||||
setFrom(undefined);
|
||||
setTo(undefined);
|
||||
}}
|
||||
>
|
||||
모드 · 날짜 초기화
|
||||
필터 초기화
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
@@ -207,8 +221,10 @@ export function MatchesPage() {
|
||||
{!data && !err && <Spinner label="경기 목록 불러오는 중" />}
|
||||
{data && all.length === 0 && (
|
||||
<div className="empty">
|
||||
{filtered
|
||||
? '고른 모드 · 날짜에 맞는 경기가 없습니다.'
|
||||
{replayUnknown
|
||||
? '리플레이 필터는 게임 PC 앱 v1.12.0 부터 됩니다. 앱을 업데이트해 주세요.'
|
||||
: filtered
|
||||
? '고른 필터에 맞는 경기가 없습니다.'
|
||||
: has === 'voice'
|
||||
? '목소리가 녹음된 경기가 없습니다.'
|
||||
: has === 'timeline'
|
||||
|
||||
Reference in New Issue
Block a user