refactor(client-side): add debounced versions of functions

split autoEdit and autoSave into debounced and non-debounced versions
This commit is contained in:
parent 1447960b1a
commit dba62b4677
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

@ -3,7 +3,7 @@ import { message } from "ant-design-vue";
import { IStory } from "@models/stories"; import { IStory } from "@models/stories";
import { useAutoSaveStore } from "~/stores/autosaveStore"; import { useAutoSaveStore } from "~/stores/autosaveStore";
export const autoSave = debounce(async (values: any) => { export const autoSave = async (values: any) => {
const store = useAutoSaveStore(); const store = useAutoSaveStore();
const fid = store.$state.fetchId; const fid = store.$state.fetchId;
if (store.$state.fetchId !== fid) return; if (store.$state.fetchId !== fid) return;
@ -25,10 +25,13 @@ export const autoSave = debounce(async (values: any) => {
body: values, body: values,
}); });
} }
}, 20000); };
export const autoEdit = debounce( export const autoEdit = (
(values: any, endpoint: string, method: "put" | "post") => { values: any,
endpoint: string,
method: "put" | "post",
) => {
const [messageApi, contextHolder] = message.useMessage(); const [messageApi, contextHolder] = message.useMessage();
useApiFetch<{ success: boolean; data: IStory }>(endpoint, { useApiFetch<{ success: boolean; data: IStory }>(endpoint, {
method, method,
@ -40,6 +43,7 @@ export const autoEdit = debounce(
messageApi.error("Error saving data."); messageApi.error("Error saving data.");
} }
}); });
}, };
10000,
); export const debouncedAutoEdit = debounce(autoEdit, 5000);
export const debouncedAutoSave = debounce(autoSave, 10000);