feat: Visually differentiate unread documents (#1507)

* feat: Visually differentiate unread documents

* feat: add document treatment in document preview

* fix requested changes

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Guilherme DIniz
2020-09-21 02:32:28 -03:00
committed by GitHub
parent 4ffc04bc5d
commit d487da8f15
12 changed files with 80 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
// @flow
import addDays from "date-fns/add_days";
import differenceInDays from "date-fns/difference_in_days";
import invariant from "invariant";
import { action, computed, observable, set } from "mobx";
import parseTitle from "shared/utils/parseTitle";
@@ -7,6 +8,7 @@ import unescape from "shared/utils/unescape";
import DocumentsStore from "stores/DocumentsStore";
import BaseModel from "models/BaseModel";
import User from "models/User";
import View from "./View";
type SaveOptions = {
publish?: boolean,
@@ -23,7 +25,7 @@ export default class Document extends BaseModel {
collaborators: User[];
collectionId: string;
lastViewedAt: ?string;
@observable lastViewedAt: ?string;
createdAt: string;
createdBy: User;
updatedAt: string;
@@ -47,7 +49,7 @@ export default class Document extends BaseModel {
constructor(fields: Object, store: DocumentsStore) {
super(fields, store);
if (this.isNew && this.isFromTemplate) {
if (this.isNewDocument && this.isFromTemplate) {
this.title = "";
}
}
@@ -72,6 +74,14 @@ export default class Document extends BaseModel {
return !!this.lastViewedAt && this.lastViewedAt < this.updatedAt;
}
@computed
get isNew(): boolean {
return (
!this.lastViewedAt &&
differenceInDays(new Date(), new Date(this.createdAt)) < 14
);
}
@computed
get isStarred(): boolean {
return !!this.store.starredIds.get(this.id);
@@ -112,7 +122,7 @@ export default class Document extends BaseModel {
}
@computed
get isNew(): boolean {
get isNewDocument(): boolean {
return this.createdAt === this.updatedAt;
}
@@ -199,6 +209,11 @@ export default class Document extends BaseModel {
return this.store.rootStore.views.create({ documentId: this.id });
};
@action
updateLastViewed = (view: View) => {
this.lastViewedAt = view.lastViewedAt;
};
@action
templatize = async () => {
return this.store.templatize(this.id);