fix: Race condition updating document breadcrumb
This commit is contained in:
@@ -86,11 +86,7 @@ const DocumentBreadcrumb: React.FC<Props> = ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = React.useMemo(
|
const path = document.pathTo;
|
||||||
() => collection?.pathToDocument(document.id).slice(0, -1) || [],
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
[collection, document, document.collectionId, document.parentDocumentId]
|
|
||||||
);
|
|
||||||
|
|
||||||
const items = React.useMemo(() => {
|
const items = React.useMemo(() => {
|
||||||
const output = [];
|
const output = [];
|
||||||
@@ -103,7 +99,7 @@ const DocumentBreadcrumb: React.FC<Props> = ({
|
|||||||
output.push(collectionNode);
|
output.push(collectionNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
path.forEach((node: NavigationNode) => {
|
path.slice(0, -1).forEach((node: NavigationNode) => {
|
||||||
output.push({
|
output.push({
|
||||||
type: "route",
|
type: "route",
|
||||||
title: node.emoji ? (
|
title: node.emoji ? (
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ import DocumentsStore from "~/stores/DocumentsStore";
|
|||||||
import User from "~/models/User";
|
import User from "~/models/User";
|
||||||
import { client } from "~/utils/ApiClient";
|
import { client } from "~/utils/ApiClient";
|
||||||
import { settingsPath } from "~/utils/routeHelpers";
|
import { settingsPath } from "~/utils/routeHelpers";
|
||||||
|
import Collection from "./Collection";
|
||||||
import View from "./View";
|
import View from "./View";
|
||||||
import ParanoidModel from "./base/ParanoidModel";
|
import ParanoidModel from "./base/ParanoidModel";
|
||||||
import Field from "./decorators/Field";
|
import Field from "./decorators/Field";
|
||||||
|
import Relation from "./decorators/Relation";
|
||||||
|
|
||||||
type SaveOptions = {
|
type SaveOptions = {
|
||||||
publish?: boolean;
|
publish?: boolean;
|
||||||
@@ -59,6 +61,12 @@ export default class Document extends ParanoidModel {
|
|||||||
@observable
|
@observable
|
||||||
collectionId?: string | null;
|
collectionId?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The comment that this comment is a reply to.
|
||||||
|
*/
|
||||||
|
@Relation(() => Collection, { onDelete: "cascade" })
|
||||||
|
collection?: Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The text content of the document as Markdown.
|
* The text content of the document as Markdown.
|
||||||
*/
|
*/
|
||||||
@@ -276,6 +284,11 @@ export default class Document extends ParanoidModel {
|
|||||||
return floor((this.tasks.completed / this.tasks.total) * 100);
|
return floor((this.tasks.completed / this.tasks.total) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@computed
|
||||||
|
get pathTo() {
|
||||||
|
return this.collection?.pathToDocument(this.id) ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
get titleWithDefault(): string {
|
get titleWithDefault(): string {
|
||||||
return this.title || i18n.t("Untitled");
|
return this.title || i18n.t("Untitled");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user