feat: add filters to drafts (#1631)

* feat: add filters to drafts

Co-authored-by: Guilherme Diniz <guilhermedassumpcao@gmail.com>
This commit is contained in:
Tom Moor
2020-11-08 22:33:52 -08:00
committed by GitHub
parent 14e0ed8108
commit 4e7a1cd121
7 changed files with 184 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ import invariant from "invariant";
import { find, orderBy, filter, compact, omitBy } from "lodash";
import { observable, action, computed, runInAction } from "mobx";
import { MAX_TITLE_LENGTH } from "shared/constants";
import { subtractDate } from "shared/utils/date";
import naturalSort from "shared/utils/naturalSort";
import BaseStore from "stores/BaseStore";
import RootStore from "stores/RootStore";
@@ -168,12 +169,31 @@ export default class DocumentsStore extends BaseStore<Document> {
}
@computed
get drafts(): Document[] {
return filter(
get totalDrafts(): number {
return this.drafts().length;
}
drafts = (options = {}): Document[] => {
let drafts = filter(
orderBy(this.all, "updatedAt", "desc"),
(doc) => !doc.publishedAt
);
}
if (options.dateFilter) {
drafts = filter(
drafts,
(draft) =>
new Date(draft.updatedAt) >=
subtractDate(new Date(), options.dateFilter)
);
}
if (options.collectionId) {
drafts = filter(drafts, { collectionId: options.collectionId });
}
return drafts;
};
@computed
get active(): ?Document {