feat: add hub
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
function capitalize(word: string): string {
|
||||
return word.charAt(0).toUpperCase() + word.slice(1)
|
||||
}
|
||||
|
||||
export function useSaveEntry(options: { url: string, dataKey: string | string[], noun: string, onSaved: () => void }) {
|
||||
export function useSaveEntry(options: { url: string, dataKey: string | string[], saved: string, failed: string, onSaved: () => void }) {
|
||||
const toast = useToast()
|
||||
const saving = ref(false)
|
||||
|
||||
@@ -11,11 +7,11 @@ export function useSaveEntry(options: { url: string, dataKey: string | string[],
|
||||
try {
|
||||
await $fetch(options.url, { method: 'POST', body })
|
||||
await refreshNuxtData(options.dataKey)
|
||||
toast.add({ title: `${capitalize(options.noun)} saved`, color: 'success', icon: 'i-lucide-check' })
|
||||
toast.add({ title: options.saved, color: 'success', icon: 'i-lucide-check' })
|
||||
options.onSaved()
|
||||
} catch (error) {
|
||||
toast.add({
|
||||
title: `Couldn't save the ${options.noun}`,
|
||||
title: options.failed,
|
||||
description: errorMessage(error),
|
||||
color: 'error',
|
||||
icon: 'i-lucide-triangle-alert'
|
||||
|
||||
Reference in New Issue
Block a user