Moved delete note to composable

main
TZGyn 2 years ago
parent de00040a8a
commit 355a7ab56a
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -29,6 +29,23 @@ const submitNote = async (note: unknown, noteId: string | string[]) => {
return response return response
} }
const deleteNote = async (noteId: string | string[]) => {
let response
await useFetch('/api/note', {
method: 'DELETE',
query: {
id: noteId,
},
onResponse({ response }) {
console.log('DELETE:', response._data.message)
response = response._data
},
})
return response
}
type Note = z.infer<typeof noteSchema> type Note = z.infer<typeof noteSchema>
const useNote = () => const useNote = () =>
@ -36,4 +53,4 @@ const useNote = () =>
const useDescription = () => useState<string>('description', () => '') const useDescription = () => useState<string>('description', () => '')
export { submitNote, useNote, useDescription } export { deleteNote, submitNote, useDescription, useNote }

@ -76,19 +76,12 @@ const submit = async () => {
}, 1000) }, 1000)
} }
const deleteNote = async () => { const remove = async () => {
isDeleting.value = true isDeleting.value = true
await useFetch('/api/note', {
method: 'DELETE', await deleteNote(route.params.id)
query: {
id: route.params.id, isDeleting.value = false
},
onResponse({ response }) {
isDeleting.value = false
console.log('DELETE:', response._data.message)
router.push('/notes')
},
})
} }
onMounted(() => { onMounted(() => {

Loading…
Cancel
Save