feat: Optional branding on shared documents (#4450)

* feat: Optional branding on shared documents

* Refactor
Remove unneccessarily exposed team id
Remove top-level collapsible document on publicly shared urls

* fix: Branding disappears when revising document
fix: Clicking title should go back to main app when logged in
This commit is contained in:
Tom Moor
2022-11-21 16:20:50 -08:00
committed by GitHub
parent 088ef81133
commit e605961e23
13 changed files with 91 additions and 40 deletions

View File

@@ -10,6 +10,7 @@ import { DocumentValidation } from "@shared/validations";
import BaseStore from "~/stores/BaseStore";
import RootStore from "~/stores/RootStore";
import Document from "~/models/Document";
import Team from "~/models/Team";
import env from "~/env";
import {
FetchOptions,
@@ -40,7 +41,10 @@ type ImportOptions = {
};
export default class DocumentsStore extends BaseStore<Document> {
sharedTreeCache: Map<string, NavigationNode | undefined> = new Map();
sharedCache: Map<
string,
{ sharedTree: NavigationNode; team: Team } | undefined
> = new Map();
@observable
searchCache: Map<string, SearchResult[] | undefined> = new Map();
@@ -265,7 +269,7 @@ export default class DocumentsStore extends BaseStore<Document> {
}
getSharedTree(documentId: string): NavigationNode | undefined {
return this.sharedTreeCache.get(documentId);
return this.sharedCache.get(documentId)?.sharedTree;
}
@action
@@ -466,6 +470,7 @@ export default class DocumentsStore extends BaseStore<Document> {
options: FetchOptions = {}
): Promise<{
document: Document;
team?: Team;
sharedTree?: NavigationNode;
}> => {
if (!options.prefetch) {
@@ -482,10 +487,10 @@ export default class DocumentsStore extends BaseStore<Document> {
return {
document: doc,
};
} else if (this.sharedTreeCache.has(options.shareId)) {
} else if (this.sharedCache.has(options.shareId)) {
return {
document: doc,
sharedTree: this.sharedTreeCache.get(options.shareId),
...this.sharedCache.get(options.shareId),
};
}
}
@@ -504,10 +509,14 @@ export default class DocumentsStore extends BaseStore<Document> {
invariant(document, "Document not available");
if (options.shareId) {
this.sharedTreeCache.set(options.shareId, res.data.sharedTree);
this.sharedCache.set(options.shareId, {
sharedTree: res.data.sharedTree,
team: res.data.team,
});
return {
document,
sharedTree: res.data.sharedTree,
team: res.data.team,
};
}