File size: 1,114 Bytes
65d68f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import { apiGet, apiPost } from "@/lib/api/client";
import { hasLiveSession } from "@/lib/api/mode";
import type { Phase3Activity } from "@/lib/phase3-learning";
/**
* Backend persistence for the learning-support activity aggregate (PYQ result,
* weak topics, revision saves, recovery actions). localStorage stays the
* offline source of truth; this makes the data survive login / device change.
* Best-effort, no-op when logged out.
*/
type Phase3ActivityRemote = { data: Phase3Activity; updated_at: string };
export async function savePhase3ActivityRemote(data: Phase3Activity): Promise<boolean> {
if (!hasLiveSession()) return false;
try {
await apiPost<Phase3ActivityRemote, { data: Phase3Activity }>("/phase3-activity", { data });
return true;
} catch {
return false;
}
}
export async function getPhase3ActivityRemote(): Promise<Phase3Activity | null> {
if (!hasLiveSession()) return null;
try {
const remote = await apiGet<Phase3ActivityRemote | null>(
"/phase3-activity/me?optional=true",
);
return remote?.data ?? null;
} catch {
return null;
}
}
|