diff --git a/lib/client/utils.ts b/lib/client/utils.ts index e8f9178..8c71bf4 100644 --- a/lib/client/utils.ts +++ b/lib/client/utils.ts @@ -3,7 +3,7 @@ import { message } from "ant-design-vue"; import { IStory } from "@models/stories"; import { useAutoSaveStore } from "~/stores/autosaveStore"; -export const autoSave = debounce(async (values: any) => { +export const autoSave = async (values: any) => { const store = useAutoSaveStore(); const fid = store.$state.fetchId; if (store.$state.fetchId !== fid) return; @@ -25,21 +25,25 @@ export const autoSave = debounce(async (values: any) => { body: values, }); } -}, 20000); +}; -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, -); +export const autoEdit = ( + 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."); + } + }); +}; + +export const debouncedAutoEdit = debounce(autoEdit, 5000); +export const debouncedAutoSave = debounce(autoSave, 10000);