mirror of
https://github.com/myronblair/web-dashboard
synced 2026-06-30 17:50:10 -05:00
fix: notes always re-fetch from server after mutation so UI stays in sync
This commit is contained in:
+9
-12
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user