diff --git a/lib/client/utils.ts b/lib/client/utils.ts index 20756aa..7702595 100644 --- a/lib/client/utils.ts +++ b/lib/client/utils.ts @@ -1,4 +1,6 @@ import { debounce } from "lodash-es"; +import { message } from "ant-design-vue"; +import { IStory } from "~/models/stories"; import { useAutoSaveStore } from "~/stores/autosaveStore"; export const autoSave = debounce((values: any) => { @@ -19,3 +21,20 @@ export const autoSave = debounce((values: any) => { }); } }, 3000); + +export const autoEdit = debounce( + (values: any, endpoint: string, method: "put" | "post") => { + const [messageApi, contextHolder] = message.useMessage(); + useApiFetch<{ success: boolean; data: IStory }>(endpoint, { + method, + body: values, + }).then(({ data, error }) => { + if (data.value?.success) { + messageApi.success("Your work has been saved successfully."); + } else if (error) { + messageApi.error("Error saving data."); + } + }); + }, + 10000, +);