add/delete notes

This commit is contained in:
Michael Dausmann
2023-04-14 00:24:22 +10:00
parent 6a7e7ec9ac
commit 8b2348f6a3
5 changed files with 55 additions and 6 deletions

View File

@@ -26,10 +26,26 @@ export const useNotesStore = defineStore('notes', () => {
}
}
async function createNote(note_text: string) {
const { $client } = useNuxtApp();
const { note } = await $client.notes.createNote.mutate({note_text});
if(note){
_notes.value.push(note);
}
}
async function deleteNote(note_id: number) {
const { $client } = useNuxtApp();
const { note } = await $client.notes.deleteNote.mutate({note_id});
if(note){
_notes.value = _notes.value.filter(n => n.id !== note.id);
}
}
// if the active account changes, fetch notes again (i.e dynamic.. probabl overkill)
watch(activeAccountId, async (val, oldVal)=> {
await fetchNotesForCurrentUser()
});
return { notes: _notes, fetchNotesForCurrentUser }
return { notes: _notes, fetchNotesForCurrentUser, createNote, deleteNote }
});