fix: Sidebar jumps when publish or unpublish document (#4706)
* Return updated collection in API response for documents.unpublish and documents.update Allows for improved UX on clientside * test * tsc * tsc
This commit is contained in:
@@ -194,8 +194,17 @@ const Link = styled(NavLink)<{
|
||||
${(props) =>
|
||||
props.$isDraft &&
|
||||
css`
|
||||
padding: 4px 14px;
|
||||
border: 1px dashed ${props.theme.sidebarDraftBorder};
|
||||
&:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
border-radius: 4px;
|
||||
border: 1.5px dashed ${props.theme.sidebarDraftBorder};
|
||||
}
|
||||
`}
|
||||
|
||||
svg {
|
||||
|
||||
@@ -686,15 +686,24 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
lastRevision: number;
|
||||
}
|
||||
) {
|
||||
const document = await super.update(params, options);
|
||||
this.isSaving = true;
|
||||
|
||||
// Because the collection object contains the url and title
|
||||
// we need to ensure they are updated there as well.
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
if (collection) {
|
||||
collection.updateDocument(document);
|
||||
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?.updateFromJson(res.data.collection);
|
||||
return document;
|
||||
} finally {
|
||||
this.isSaving = false;
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -763,16 +772,16 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
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.updateFromJson(res.data);
|
||||
document.updateFromJson(res.data.document);
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
collection?.updateFromJson(res.data.collection);
|
||||
this.addPolicies(res.policies);
|
||||
});
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
if (collection) {
|
||||
collection.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
star = (document: Document) => {
|
||||
|
||||
Reference in New Issue
Block a user