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:
parent
65195289bd
commit
bb4ca8ae40
@ -31,10 +31,20 @@ function BattleTable({
|
|||||||
score: '',
|
score: '',
|
||||||
name: '-',
|
name: '-',
|
||||||
}], [list]);
|
}], [list]);
|
||||||
const resultMap = useMemo(() => new Map<string, {
|
const resultMap = useMemo(() => {
|
||||||
winer: string,
|
const cache = localStorage.getItem('match-result-map');
|
||||||
score: number,
|
const cacheEntries: [string, { winer: string, score: number }][] = cache ? Object.entries(JSON.parse(cache)) : [];
|
||||||
}>(), []);
|
return new Map<string, {
|
||||||
|
winer: string,
|
||||||
|
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>>([]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user