From e13f9de5d3c2427f348d3c474a79f29aeaa79e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 11 Oct 2023 16:38:20 -0400 Subject: [PATCH] feat(client-side): complete other debounced autosave function (this is for editing stories) --- lib/client/utils.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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, +);