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
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user