feat: add A-card operations frontend and backend foundation

This commit is contained in:
郑龙捷
2026-09-02 09:54:03 +08:00
parent 9badd3597f
commit ad71259ba5
106 changed files with 12461 additions and 1796 deletions
@@ -0,0 +1,24 @@
import { type Dispatch, type SetStateAction, useEffect, useState } from "react";
export function usePersistentState<T>(key: string, initialValue: T | (() => T)): [T, Dispatch<SetStateAction<T>>] {
const [value, setValue] = useState<T>(() => {
const fallback = typeof initialValue === "function" ? (initialValue as () => T)() : initialValue;
if (typeof window === "undefined") return fallback;
try {
const stored = window.localStorage.getItem(key);
return stored ? JSON.parse(stored) as T : fallback;
} catch {
return fallback;
}
});
useEffect(() => {
try {
window.localStorage.setItem(key, JSON.stringify(value));
} catch {
// Storage can be unavailable in private mode; in-memory state still works.
}
}, [key, value]);
return [value, setValue];
}