function notesApp(initialNotes, albumId) { return { open: false, notes: initialNotes, status: '', saveTimer: null, scheduleAutosave() { clearTimeout(this.saveTimer); this.status = 'Saving…'; this.saveTimer = setTimeout(() => this.doSave(), 500); }, async doSave() { const res = await fetch('/notes/save', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ album_id: albumId, notes: this.notes }), }); this.status = res.ok ? 'Saved ✓' : 'Error'; }, async convertToEntry(text) { const res = await fetch('/group/from-note', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ album_id: albumId, text }), }); if (res.ok) { this.status = 'Added as entry ✓'; } }, }; }