autosave for existing notes

This commit is contained in:
schmeeve
2026-09-23 17:27:37 -07:00
parent c2436f39ea
commit 0a13fed4a2

View File

@@ -470,7 +470,6 @@ function renderEditor(body, owner) {
const isNew = !state.noteId; const isNew = !state.noteId;
const back = el("button", { class: "btn ghost", text: "← Back", onclick: exitEditor }); const back = el("button", { class: "btn ghost", text: "← Back", onclick: exitEditor });
const save = isNew ? null : el("button", { class: "btn primary", text: "Save", onclick: saveNote });
const del = state.noteId ? el("button", { class: "btn danger", text: "Delete", onclick: deleteNote }) : null; const del = state.noteId ? el("button", { class: "btn danger", text: "Delete", onclick: deleteNote }) : null;
const hist = state.noteId ? el("button", { class: "btn ghost", text: "History", onclick: showHistory }) : null; const hist = state.noteId ? el("button", { class: "btn ghost", text: "History", onclick: showHistory }) : null;
@@ -513,7 +512,7 @@ function renderEditor(body, owner) {
const attach = el("button", { class: "btn", text: "Attach", onclick: () => fileInput.click() }); const attach = el("button", { class: "btn", text: "Attach", onclick: () => fileInput.click() });
const wrap = el("div", { class: "editor-wrap" }, [ const wrap = el("div", { class: "editor-wrap" }, [
el("div", { class: "editor-topbar" }, [back, ...(isNew ? [] : [spaceSel]), el("div", { class: "spacer" }), attach, hist, del, commonLabel, previewBtn, ...(isNew ? [] : [save])]), el("div", { class: "editor-topbar" }, [back, ...(isNew ? [] : [spaceSel]), el("div", { class: "spacer" }), attach, hist, del, commonLabel, previewBtn]),
toolbar, toolbar,
split, split,
hint, hint,
@@ -583,18 +582,12 @@ async function persistNote() {
} catch (e) { status.textContent = "Error: " + e.message; } } catch (e) { status.textContent = "Error: " + e.message; }
} }
async function saveNote() {
const isNew = !state.noteId;
await persistNote();
if (isNew) showHome();
}
function editorIsEmpty() { function editorIsEmpty() {
return !state.editor || state.editor.getText().trim() === ""; return !state.editor || state.editor.getText().trim() === "";
} }
async function exitEditor() { async function exitEditor() {
if (!state.noteId && !editorIsEmpty()) { if (state.noteId || !editorIsEmpty()) {
await persistNote(); await persistNote();
} }
showHome(); showHome();