fix: notes always re-fetch from server after mutation so UI stays in sync

This commit is contained in:
2026-06-22 05:38:01 +00:00
parent 21bec5537a
commit f1bee91880
+9 -12
View File
@@ -463,34 +463,31 @@
if (!txt) { document.getElementById('note-input').focus(); return; } if (!txt) { document.getElementById('note-input').focus(); return; }
const btn = document.querySelector('.btn-note-add'); const btn = document.querySelector('.btn-note-add');
btn.disabled = true; btn.disabled = true;
const r = await notesApi('add', { text: txt, detail: det }); await notesApi('add', { text: txt, detail: det });
btn.disabled = false; btn.disabled = false;
if (r.ok) { document.getElementById('note-input').value = '';
_notes.unshift(r.note); document.getElementById('note-detail').value = '';
document.getElementById('note-input').value = ''; document.getElementById('note-detail').style.display = 'none';
document.getElementById('note-detail').value = ''; document.getElementById('note-detail-toggle').textContent = '+ Add details';
document.getElementById('note-detail').style.display = 'none'; await fetchNotes();
document.getElementById('note-detail-toggle').textContent = '+ Add details';
renderNotes();
}
} }
async function toggleNote(id) { async function toggleNote(id) {
_notes = _notes.map(n => n.id === id ? {...n, done: !n.done} : n); _notes = _notes.map(n => n.id === id ? {...n, done: !n.done} : n);
renderNotes(); renderNotes();
await notesApi('toggle', { id }); notesApi('toggle', { id }).then(fetchNotes);
} }
async function deleteNote(id) { async function deleteNote(id) {
_notes = _notes.filter(n => n.id !== id); _notes = _notes.filter(n => n.id !== id);
renderNotes(); renderNotes();
await notesApi('delete', { id }); notesApi('delete', { id }).then(fetchNotes);
} }
async function clearDone() { async function clearDone() {
_notes = _notes.filter(n => !n.done); _notes = _notes.filter(n => !n.done);
renderNotes(); renderNotes();
await notesApi('clear-done'); notesApi('clear-done').then(fetchNotes);
} }
function toggleDetail() { function toggleDetail() {