add local storage in json for collection

This commit is contained in:
2025-08-17 12:58:16 +01:00
parent 0260afb152
commit 0b6c687f7f
4 changed files with 116 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
"use client";
import React, { useEffect, useMemo, useState } from 'react';
import type { TcgCard } from '@/types/pokemon';
import { loadChecklist, saveChecklist } from '@/lib/checklist';
import { loadChecklistServer, saveChecklistServer } from '@/lib/checklist';
import type { ChecklistV2, VariantKey } from '@/lib/checklist';
import CardGrid from '@/components/CardGrid';
import Header from '@/components/Header';
@@ -18,7 +18,10 @@ export default function Page() {
const [tab, setTab] = useState<'uncollected' | 'collected'>('uncollected');
useEffect(() => {
setChecklist(loadChecklist());
(async () => {
const data = await loadChecklistServer();
setChecklist(data);
})();
}, []);
useEffect(() => {
@@ -48,7 +51,8 @@ export default function Page() {
// Clean up empty records to keep storage tidy
const hasAny = Object.values(current).some(Boolean);
if (hasAny) next[id] = current; else delete next[id];
saveChecklist(next);
// fire-and-forget save to server; fallback handled in lib
void saveChecklistServer(next);
return next;
});
}