feat: add localStorage persistence for battle result map

- Initialize `resultMap` from `localStorage` on component mount if data exists.
- Save updated `resultMap` back to `localStorage` when the component unmounts.
- Removed debug console.log statement for cleaner logs.
This commit is contained in:
kyuuseiryuu 2026-03-10 17:21:44 +09:00
parent 65195289bd
commit bb4ca8ae40

View File

@ -31,10 +31,20 @@ function BattleTable({
score: '', score: '',
name: '-', name: '-',
}], [list]); }], [list]);
const resultMap = useMemo(() => new Map<string, { const resultMap = useMemo(() => {
const cache = localStorage.getItem('match-result-map');
const cacheEntries: [string, { winer: string, score: number }][] = cache ? Object.entries(JSON.parse(cache)) : [];
return new Map<string, {
winer: string, winer: string,
score: number, score: number,
}>(), []); }>(cacheEntries);
}, []);
useEffect(() => {
return () => {
const cache = JSON.stringify(Object.fromEntries(resultMap.entries()));
localStorage.setItem('match-result-map', cache);
}
}, [resultMap]);
const buildMatchGroupTable = useCallback((list: (BasePlayer | null)[]) => { const buildMatchGroupTable = useCallback((list: (BasePlayer | null)[]) => {
const roundNum = list.length - 1; const roundNum = list.length - 1;
const dataList = cloneDeep(list); const dataList = cloneDeep(list);
@ -57,7 +67,6 @@ function BattleTable({
}); });
return cloneDeep([left, right]); return cloneDeep([left, right]);
}); });
console.debug(roundTable);
return roundTable.filter(Boolean); return roundTable.filter(Boolean);
}, []); }, []);
const [matchGroupTable, setMatchGroupTable] = useState<ReturnType<typeof buildMatchGroupTable>>([]); const [matchGroupTable, setMatchGroupTable] = useState<ReturnType<typeof buildMatchGroupTable>>([]);