DocDoeAI / src /lib /api /phase3-activity.ts
asnannp's picture
deploy: sync backend to Space root (learn-lesson HF cache fix)
65d68f5
Raw History Blame Contribute Delete
1.11 kB
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;
}
}