- Study cards say whether the Bible text works offline, with a button to save the missing book (notes are always kept on the device). - Each note keeps its last 12 versions with Restore (History under each note). - Keyboard-only study: 1/2/3 write in Observe/Interpret/Apply, C/W/X/P switch resource tabs, V compares, Esc leaves a note box; listed under "?". - Export > Import notes: bring Word/Markdown/text notes into the matching chunks without overwriting anything; can mark them as not your own. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
24 lines
1.2 KiB
JavaScript
24 lines
1.2 KiB
JavaScript
// Earlier versions of a single note (Observe, Interpret, Apply…), kept on this device so one note can be rolled
|
|
// back without restoring the whole study. A version is saved when you start and when you stop editing a note, so
|
|
// whatever was there before a big rewrite is always a click away.
|
|
export const MAX_VERSIONS = 12;
|
|
const keyFor = (chunkId, field) => `note-history:${chunkId}:${field}`;
|
|
|
|
// -> [{ at, text }], newest first
|
|
export function listNoteVersions(chunkId, field) {
|
|
try {
|
|
const raw = JSON.parse(localStorage.getItem(keyFor(chunkId, field)) || '[]');
|
|
return Array.isArray(raw) ? raw.filter((v) => v && typeof v.text === 'string') : [];
|
|
} catch { return []; }
|
|
}
|
|
|
|
// Keeps `text` as the newest version unless it is blank or the same as the newest one. Returns the list.
|
|
export function recordNoteVersion(chunkId, field, text, now = Date.now()) {
|
|
const list = listNoteVersions(chunkId, field);
|
|
const value = text ?? '';
|
|
if (!value.trim() || list[0]?.text === value) return list;
|
|
const next = [{ at: now, text: value }, ...list].slice(0, MAX_VERSIONS);
|
|
try { localStorage.setItem(keyFor(chunkId, field), JSON.stringify(next)); } catch { /* storage full or unavailable */ }
|
|
return next;
|
|
}
|