1. Bugs fixed:
- Backup schema now accepts theme: "aero" so backups exported under
Frutiger Aero pass parseBackup on import, and applyImport in "replace"
mode replaces SRS schedules, answer history, and chats instead of
merging into existing SRS or skipping empty arrays.
- Typed FillBlank cards bind the input value to chosen ?? value instead
of chosen ?? "", and normalise() preserves Unicode letters (\p{L}\p{N})
when grading non-ASCII answers.
- OpenAI-compatible vision calls (contentFor in lib/openai-compat.ts)
prefix data:image/jpeg;base64, when routes pass stripped base64.
- Streaming calls (ollamaChatStream, providerChatStream) keep their
AbortController active across the entire body stream and API routes
forward request.signal so stopping a chat or cancelling a run aborts
the upstream request immediately.
- HomeworkCard uses homeworkModeLabelKey so "check" records display the
Checked label instead of Step-by-step guide.
- Desktop dropzones on /create and /homework accept dropped documents as
well as images.
- LibraryScreen filters reported questions out of its due and mistake
counts to match ReviewClient.
- Clearing a provider key resets generation if it pointed at that
provider; chat conversations persist and restore provider; ModelPicker
keys items by provider:name.
- RouteTransition no longer mutates module-level lastPath during render.
- Service worker asset handler falls back to Response.error() when an
uncached asset fetch fails offline.
- Confetti and .ice-orb / .ice-bubble respect the in-app reduce-motion
toggle.
2. Performance & cleanup:
- Deduplicate window storage listeners across all six localStorage
stores (one listener while subscribed instead of N^2 notifications).
- Use todayAnswerCount in LibraryScreen and pass sorted folders to
DeckCard.
- Memoize MessageRow with stable callbacks in ChatScreen and compute
last message IDs in a single pass.
- Close ImageBitmap after drawing in lib/image.ts and destroy pdf.js
documents in finally in lib/documents.ts.
- Avoid re-parsing serialized sync payloads in POST /api/sync.
- Deduplicate copyText (lib/share.ts -> lib/clipboard.ts), chatMessageId,
describeExtraction, ALL_FOLDERS, useIsPhone, and remove unused helpers
and boilerplate public/*.svg files.
Version 0.5.8, SW -> freezmo-v80.
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* Draft persistence for the wizards, so an OS kill (or an accidental reload)
|
|
* doesn't lose the user's photos, pasted text or options. Best-effort: photo
|
|
* data URLs can be large, so every write is guarded and skipped on quota
|
|
* errors instead of breaking the flow.
|
|
*/
|
|
|
|
export type WizardDraft = {
|
|
v: 1;
|
|
savedAt: number;
|
|
text?: string;
|
|
focus?: string;
|
|
difficulty?: string;
|
|
count?: number;
|
|
folderId?: string;
|
|
images?: Array<{ id: string; name: string; dataUrl: string; bytes: number; width: number; height: number }>;
|
|
};
|
|
|
|
const TTL_MS = 24 * 60 * 60 * 1000;
|
|
const MAX_BYTES = 3_000_000;
|
|
|
|
function keyFor(scope: "deck" | "homework"): string {
|
|
return `freezmo.draft.${scope}.v1`;
|
|
}
|
|
|
|
export function saveWizardDraft(scope: "deck" | "homework", draft: Omit<WizardDraft, "v" | "savedAt">): void {
|
|
try {
|
|
const images = draft.images ?? [];
|
|
const size = images.reduce((sum, image) => sum + image.dataUrl.length, 0);
|
|
const payload: WizardDraft = {
|
|
v: 1,
|
|
savedAt: Date.now(),
|
|
...draft,
|
|
// Photos over the budget are dropped rather than failing the whole save.
|
|
images: size > MAX_BYTES ? [] : images,
|
|
};
|
|
window.localStorage.setItem(keyFor(scope), JSON.stringify(payload));
|
|
} catch {
|
|
/* quota or private mode — drafts are a nice-to-have */
|
|
}
|
|
}
|
|
|
|
export function loadWizardDraft(scope: "deck" | "homework"): WizardDraft | null {
|
|
try {
|
|
const raw = window.localStorage.getItem(keyFor(scope));
|
|
if (!raw) return null;
|
|
const parsed = JSON.parse(raw) as WizardDraft;
|
|
if (parsed.v !== 1 || Date.now() - parsed.savedAt > TTL_MS) {
|
|
window.localStorage.removeItem(keyFor(scope));
|
|
return null;
|
|
}
|
|
return parsed;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function clearWizardDraft(scope: "deck" | "homework"): void {
|
|
try {
|
|
window.localStorage.removeItem(keyFor(scope));
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|