refactor(client-side): make autoEdit and autoSave functions fully async
This commit is contained in:
parent
aa5dc23dfa
commit
08ce2175cd
@ -9,36 +9,33 @@ export const autoSave = async (values: any) => {
|
||||
if (store.$state.fetchId !== fid) return;
|
||||
store.$patch({ fetchId: store.$state.fetchId + 1 });
|
||||
if (store.$state.draftId == undefined) {
|
||||
let b = useApiFetch<{ draftId: number; success: boolean }>("/drafts/new", {
|
||||
let { data, error } = await useApiFetch<{ draftId: number; success: boolean }>("/drafts/new", {
|
||||
method: "post",
|
||||
body: values,
|
||||
}).then(({ data, error }) => {
|
||||
console.log("fibberty", data, error);
|
||||
if (data.value) {
|
||||
store.$patch({ draftId: data.value.draftId });
|
||||
}
|
||||
});
|
||||
console.log("B", b);
|
||||
console.log("fibberty", data, error);
|
||||
if (data.value) {
|
||||
store.$patch({ draftId: data.value.draftId });
|
||||
}
|
||||
} else {
|
||||
useApiFetch<any>(`/drafts/${store.$state.draftId}`, {
|
||||
await useApiFetch<any>(`/drafts/${store.$state.draftId}`, {
|
||||
method: "put",
|
||||
body: values,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const autoEdit = (values: any, endpoint: string, method: "put" | "post") => {
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
useApiFetch<{ success: boolean; data: IStory }>(endpoint, {
|
||||
export const autoEdit = async (values: any, endpoint: string, method: "put" | "post") => {
|
||||
const [messageApi] = message.useMessage();
|
||||
const { data, error } = await 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.");
|
||||
}
|
||||
});
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user