Simplify match history with filters and persistent pagination

This commit is contained in:
2026-10-06 19:23:19 -04:00
parent 1370873cba
commit 711191c388
13 changed files with 419 additions and 103 deletions
+26
View File
@@ -0,0 +1,26 @@
import { serverIdentity } from './server-labels.js';
import type { ServerMatch } from '../match-history.js';
export function matchInstanceLabel(match: ServerMatch): string {
const identity = serverIdentity(match.server);
const parts = [identity.map !== match.map ? identity.map : '', identity.lobby === null ? '' : `Lobby ${identity.lobby}`,
match.game === 't5' ? 'Black Ops I' : match.game === 't6' ? 'Black Ops II' : match.game];
return parts.filter(Boolean).join(' · ') || match.server;
}
/** Compare calendar days in the display timezone, including DST boundaries. */
export function matchStartedLabel(value: string, zone: string, now = new Date()): string {
const date = new Date(/Z$|[+-]\d\d:\d\d$/.test(value) ? value : value.replace(' ', 'T') + 'Z');
if (!Number.isFinite(date.getTime())) return '—';
const parts = new Intl.DateTimeFormat('en-US', { timeZone: zone, year: 'numeric', month: 'numeric', day: 'numeric' });
const day = (input: Date) => {
const values = Object.fromEntries(parts.formatToParts(input).map(part => [part.type, part.value]));
return Date.UTC(Number(values.year), Number(values.month) - 1, Number(values.day));
};
const difference = day(now) - day(date);
const dateLabel = difference === 0 ? 'Today' : difference === 86400000 ? 'Yesterday'
: new Intl.DateTimeFormat('en-US', { timeZone: zone, month: 'short', day: 'numeric',
...(parts.formatToParts(now).find(p => p.type === 'year')?.value !== parts.formatToParts(date).find(p => p.type === 'year')?.value ? { year: 'numeric' as const } : {}) }).format(date);
const clock = new Intl.DateTimeFormat('en-US', { timeZone: zone, hour: 'numeric', minute: '2-digit' }).format(date);
return `${dateLabel}, ${clock}`;
}