feat: Add navigation sidebar to shared documents (#2899)
Co-authored-by: Tom Moor <tom@getoutline.com>
This commit is contained in:
@@ -11,10 +11,10 @@ import RootStore from "~/stores/RootStore";
|
||||
import Document from "~/models/Document";
|
||||
import env from "~/env";
|
||||
import {
|
||||
NavigationNode,
|
||||
FetchOptions,
|
||||
PaginationParams,
|
||||
SearchResult,
|
||||
NavigationNode,
|
||||
} from "~/types";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
|
||||
@@ -38,6 +38,8 @@ type ImportOptions = {
|
||||
};
|
||||
|
||||
export default class DocumentsStore extends BaseStore<Document> {
|
||||
sharedTreeCache: Map<string, NavigationNode | undefined> = new Map();
|
||||
|
||||
@observable
|
||||
searchCache: Map<string, SearchResult[]> = new Map();
|
||||
|
||||
@@ -262,7 +264,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
});
|
||||
};
|
||||
|
||||
getBacklinedDocuments(documentId: string): Document[] {
|
||||
getBacklinkedDocuments(documentId: string): Document[] {
|
||||
const documentIds = this.backlinks.get(documentId) || [];
|
||||
return orderBy(
|
||||
compact(documentIds.map((id) => this.data.get(id))),
|
||||
@@ -271,6 +273,10 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
);
|
||||
}
|
||||
|
||||
getSharedTree(documentId: string): NavigationNode | undefined {
|
||||
return this.sharedTreeCache.get(documentId);
|
||||
}
|
||||
|
||||
@action
|
||||
fetchChildDocuments = async (documentId: string): Promise<void> => {
|
||||
const res = await client.post(`/documents.list`, {
|
||||
@@ -468,9 +474,16 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const policy = doc ? this.rootStore.policies.get(doc.id) : undefined;
|
||||
|
||||
if (doc && policy && !options.force) {
|
||||
return {
|
||||
document: doc,
|
||||
};
|
||||
if (!options.shareId) {
|
||||
return {
|
||||
document: doc,
|
||||
};
|
||||
} else if (this.sharedTreeCache.has(options.shareId)) {
|
||||
return {
|
||||
document: doc,
|
||||
sharedTree: this.sharedTreeCache.get(options.shareId),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const res = await client.post("/documents.info", {
|
||||
@@ -486,9 +499,16 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const document = this.data.get(res.data.document.id);
|
||||
invariant(document, "Document not available");
|
||||
|
||||
if (options.shareId) {
|
||||
this.sharedTreeCache.set(options.shareId, res.data.sharedTree);
|
||||
return {
|
||||
document,
|
||||
sharedTree: res.data.sharedTree,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
document,
|
||||
sharedTree: res.data.sharedTree,
|
||||
};
|
||||
} finally {
|
||||
this.isFetching = false;
|
||||
|
||||
Reference in New Issue
Block a user