Improve reliability of document operations with websocket disconnected
This commit is contained in:
@@ -246,13 +246,17 @@ export const unpublishDocument = createAction({
|
||||
return;
|
||||
}
|
||||
|
||||
await document.unpublish();
|
||||
try {
|
||||
await document.unpublish();
|
||||
|
||||
toast.message(
|
||||
t("Unpublished {{ documentName }}", {
|
||||
documentName: document.noun,
|
||||
})
|
||||
);
|
||||
toast.success(
|
||||
t("Unpublished {{ documentName }}", {
|
||||
documentName: document.noun,
|
||||
})
|
||||
);
|
||||
} catch (err) {
|
||||
toast.error(err.message);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -651,42 +651,6 @@ export default class DocumentsStore extends Store<Document> {
|
||||
documentIds.forEach((id) => this.remove(id));
|
||||
}
|
||||
|
||||
@action
|
||||
async update(
|
||||
params: {
|
||||
id: string;
|
||||
title?: string;
|
||||
emoji?: string | null;
|
||||
text?: string;
|
||||
fullWidth?: boolean;
|
||||
templateId?: string;
|
||||
},
|
||||
options?: {
|
||||
publish?: boolean;
|
||||
done?: boolean;
|
||||
autosave?: boolean;
|
||||
}
|
||||
) {
|
||||
this.isSaving = true;
|
||||
|
||||
try {
|
||||
const res = await client.post(`/${this.apiEndpoint}.update`, {
|
||||
...params,
|
||||
...options,
|
||||
apiVersion: 2,
|
||||
});
|
||||
|
||||
invariant(res?.data, "Data should be available");
|
||||
this.addPolicies(res.policies);
|
||||
const document = this.add(res.data.document);
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
collection?.updateData(res.data.collection);
|
||||
return document;
|
||||
} finally {
|
||||
this.isSaving = false;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
async delete(
|
||||
document: Document,
|
||||
@@ -749,19 +713,29 @@ export default class DocumentsStore extends Store<Document> {
|
||||
}
|
||||
};
|
||||
|
||||
@action
|
||||
update = async (
|
||||
params: Partial<Document>,
|
||||
options?: Record<string, string | boolean | number | undefined>
|
||||
): Promise<Document> => {
|
||||
const document = await super.update(params, options);
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
void collection?.fetchDocuments({ force: true });
|
||||
return document;
|
||||
};
|
||||
|
||||
@action
|
||||
unpublish = async (document: Document) => {
|
||||
const res = await client.post("/documents.unpublish", {
|
||||
id: document.id,
|
||||
apiVersion: 2,
|
||||
});
|
||||
|
||||
runInAction("Document#unpublish", () => {
|
||||
invariant(res?.data, "Data should be available");
|
||||
document.updateData(res.data.document);
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
collection?.updateData(res.data.collection);
|
||||
document.updateData(res.data);
|
||||
this.addPolicies(res.policies);
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
void collection?.fetchDocuments({ force: true });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user