fix(client-side): fix autosave store not updating
This commit is contained in:
parent
2085131d5a
commit
c925534eb4
@ -3,24 +3,29 @@ 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((values: any) => {
|
export const autoSave = debounce(async (values: any) => {
|
||||||
const store = useAutoSaveStore();
|
const store = useAutoSaveStore();
|
||||||
|
const fid = store.$state.fetchId;
|
||||||
|
if (store.$state.fetchId !== fid) return;
|
||||||
|
store.$patch({ fetchId: store.$state.fetchId + 1 });
|
||||||
if (store.$state.draftId == undefined) {
|
if (store.$state.draftId == undefined) {
|
||||||
useApiFetch<{ draftId: number; success: boolean }>("/drafts/new", {
|
let b = useApiFetch<{ draftId: number; success: boolean }>("/drafts/new", {
|
||||||
method: "post",
|
method: "post",
|
||||||
body: values,
|
body: values,
|
||||||
}).then(({ data, error }) => {
|
}).then(({ data, error }) => {
|
||||||
|
console.log("fibberty", data, error);
|
||||||
if (data.value) {
|
if (data.value) {
|
||||||
store.$patch({ draftId: data.value.draftId });
|
store.$patch({ draftId: data.value.draftId });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
console.log("B", b);
|
||||||
} else {
|
} else {
|
||||||
useApiFetch<any>(`/drafts/${store.$state.draftId}`, {
|
useApiFetch<any>(`/drafts/${store.$state.draftId}`, {
|
||||||
method: "put",
|
method: "put",
|
||||||
body: values,
|
body: values,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 20000);
|
||||||
|
|
||||||
export const autoEdit = debounce(
|
export const autoEdit = debounce(
|
||||||
(values: any, endpoint: string, method: "put" | "post") => {
|
(values: any, endpoint: string, method: "put" | "post") => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user