add separate checkboxes for variants

This commit is contained in:
2025-08-17 12:37:32 +01:00
parent b9e7e21919
commit e9f132e9dd
5 changed files with 114 additions and 28 deletions

View File

@@ -1,9 +1,15 @@
export const CHECKLIST_KEY = 'magikarp-checklist-v1';
export const CHECKLIST_KEY_V1 = 'magikarp-checklist-v1';
export const CHECKLIST_KEY_V2 = 'magikarp-checklist-v2';
export function loadChecklist(): Set<string> {
export type VariantKey = 'base' | 'holofoil' | 'reverseHolofoil';
export type VariantState = Partial<Record<VariantKey, boolean>>;
export type ChecklistV2 = Record<string, VariantState>; // cardId -> variant flags
// Legacy loader (v1)
export function loadChecklistV1(): Set<string> {
if (typeof window === 'undefined') return new Set();
try {
const raw = localStorage.getItem(CHECKLIST_KEY);
const raw = localStorage.getItem(CHECKLIST_KEY_V1);
if (!raw) return new Set();
const arr = JSON.parse(raw) as string[];
return new Set(arr);
@@ -12,10 +18,30 @@ export function loadChecklist(): Set<string> {
}
}
export function saveChecklist(set: Set<string>) {
// New storage (v2)
export function loadChecklist(): ChecklistV2 {
if (typeof window === 'undefined') return {};
try {
const v2 = localStorage.getItem(CHECKLIST_KEY_V2);
if (v2) return JSON.parse(v2) as ChecklistV2;
// migrate from v1 if present
const v1 = loadChecklistV1();
if (v1.size === 0) return {};
const migrated: ChecklistV2 = {};
v1.forEach((id) => {
migrated[id] = { base: true };
});
saveChecklist(migrated);
return migrated;
} catch {
return {};
}
}
export function saveChecklist(state: ChecklistV2) {
if (typeof window === 'undefined') return;
try {
localStorage.setItem(CHECKLIST_KEY, JSON.stringify(Array.from(set)));
localStorage.setItem(CHECKLIST_KEY_V2, JSON.stringify(state));
} catch {
// ignore
}