feat: Show drafts in sidebar when viewing (#2820)

This commit is contained in:
Tom Moor
2021-12-11 09:34:36 -08:00
committed by GitHub
parent e5b4186faa
commit 7aa4709e69
39 changed files with 445 additions and 246 deletions

View File

@@ -7,7 +7,9 @@ import unescape from "@shared/utils/unescape";
import DocumentsStore from "~/stores/DocumentsStore";
import BaseModel from "~/models/BaseModel";
import User from "~/models/User";
import { NavigationNode } from "~/types";
import View from "./View";
import Field from "./decorators/Field";
type SaveOptions = {
publish?: boolean;
@@ -28,10 +30,36 @@ export default class Document extends BaseModel {
store: DocumentsStore;
collaboratorIds: string[];
@Field
@observable
collectionId: string;
@Field
@observable
id: string;
@Field
@observable
text: string;
@Field
@observable
title: string;
@Field
@observable
template: boolean;
@Field
@observable
templateId: string | undefined;
@Field
@observable
parentDocumentId: string | undefined;
collaboratorIds: string[];
createdAt: string;
createdBy: User;
@@ -40,22 +68,8 @@ export default class Document extends BaseModel {
updatedBy: User;
id: string;
team: string;
pinned: boolean;
text: string;
title: string;
template: boolean;
templateId: string | undefined;
parentDocumentId: string | undefined;
publishedAt: string | undefined;
archivedAt: string;
@@ -76,7 +90,7 @@ export default class Document extends BaseModel {
constructor(fields: Record<string, any>, store: DocumentsStore) {
super(fields, store);
if (this.isNewDocument && this.isFromTemplate) {
if (this.isPersistedOnce && this.isFromTemplate) {
this.title = "";
}
}
@@ -122,7 +136,7 @@ export default class Document extends BaseModel {
}
@computed
get isNew(): boolean {
get isBadgedNew(): boolean {
return (
!this.lastViewedAt &&
differenceInDays(new Date(), new Date(this.createdAt)) < 14
@@ -169,7 +183,7 @@ export default class Document extends BaseModel {
}
@computed
get isNewDocument(): boolean {
get isPersistedOnce(): boolean {
return this.createdAt === this.updatedAt;
}
@@ -199,11 +213,6 @@ export default class Document extends BaseModel {
});
};
@action
updateFromJson = (data: Record<string, any>) => {
set(this, data);
};
archive = () => {
return this.store.archive(this);
};
@@ -376,6 +385,24 @@ export default class Document extends BaseModel {
return result;
};
@computed
get isActive(): boolean {
return !this.isDeleted && !this.isTemplate && !this.isArchived;
}
@computed
get asNavigationNode(): NavigationNode {
return {
id: this.id,
title: this.title,
children: this.store.orderedData
.filter((doc) => doc.parentDocumentId === this.id)
.map((doc) => doc.asNavigationNode),
url: this.url,
isDraft: this.isDraft,
};
}
download = async () => {
// Ensure the document is upto date with latest server contents
await this.fetch();