feat(client-side): complete other debounced autosave function
(this is for editing stories)
This commit is contained in:
parent
64f3bf23ea
commit
e13f9de5d3
@ -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,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user