From 76924e70f5f9eaded6bf154db94b2135971031d4 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Nov 2018 20:18:24 -0800 Subject: [PATCH] Fix ordering of recently updated documents Edited -> Updated --- app/scenes/Collection.js | 4 ++-- app/scenes/Dashboard.js | 4 ++-- app/stores/DocumentsStore.js | 44 +++++++++++++++++------------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/app/scenes/Collection.js b/app/scenes/Collection.js index cc6720efe..5d99c667c 100644 --- a/app/scenes/Collection.js +++ b/app/scenes/Collection.js @@ -62,7 +62,7 @@ class CollectionScene extends React.Component { this.collection = collection; await Promise.all([ - this.props.documents.fetchRecentlyEdited({ + this.props.documents.fetchRecentlyUpdated({ limit: 10, collection: id, }), @@ -141,7 +141,7 @@ class CollectionScene extends React.Component { ? this.props.documents.pinnedInCollection(this.collection.id) : []; const recentDocuments = this.collection - ? this.props.documents.recentlyEditedInCollection(this.collection.id) + ? this.props.documents.recentlyUpdatedInCollection(this.collection.id) : []; const hasPinnedDocuments = !!pinnedDocuments.length; diff --git a/app/scenes/Dashboard.js b/app/scenes/Dashboard.js index f73b8a980..ee7ba109c 100644 --- a/app/scenes/Dashboard.js +++ b/app/scenes/Dashboard.js @@ -59,8 +59,8 @@ class Dashboard extends React.Component { diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js index 9b8882115..168eeed25 100644 --- a/app/stores/DocumentsStore.js +++ b/app/stores/DocumentsStore.js @@ -1,7 +1,7 @@ // @flow import { observable, action, computed, ObservableMap, runInAction } from 'mobx'; import { client } from 'utils/ApiClient'; -import { map, find, orderBy, filter, uniq, sortBy } from 'lodash'; +import { map, find, orderBy, filter, compact, uniq, sortBy } from 'lodash'; import invariant from 'invariant'; import BaseStore from 'stores/BaseStore'; @@ -22,7 +22,7 @@ type FetchOptions = { class DocumentsStore extends BaseStore { @observable recentlyViewedIds: string[] = []; - @observable recentlyEditedIds: string[] = []; + @observable recentlyUpdatedIds: string[] = []; @observable data: Map = new ObservableMap([]); @observable isLoaded: boolean = false; @observable isFetching: boolean = false; @@ -31,22 +31,20 @@ class DocumentsStore extends BaseStore { @computed get recentlyViewed(): Document[] { - const docs = []; - this.recentlyViewedIds.forEach(id => { - const doc = this.getById(id); - if (doc) docs.push(doc); - }); - return docs; + return orderBy( + compact(this.recentlyViewedIds.map(id => this.getById(id))), + 'updatedAt', + 'desc' + ); } @computed - get recentlyEdited(): Document[] { - const docs = []; - this.recentlyEditedIds.forEach(id => { - const doc = this.getById(id); - if (doc) docs.push(doc); - }); - return docs; + get recentlyUpdated(): Document[] { + return orderBy( + compact(this.recentlyUpdatedIds.map(id => this.getById(id))), + 'updatedAt', + 'desc' + ); } createdByUser(userId: string): Document[] { @@ -59,12 +57,12 @@ class DocumentsStore extends BaseStore { pinnedInCollection(collectionId: string): Document[] { return filter( - this.recentlyEditedInCollection(collectionId), + this.recentlyUpdatedInCollection(collectionId), document => document.pinned ); } - recentlyEditedInCollection(collectionId: string): Document[] { + recentlyUpdatedInCollection(collectionId: string): Document[] { return orderBy( filter( this.data.values(), @@ -129,13 +127,13 @@ class DocumentsStore extends BaseStore { }; @action - fetchRecentlyEdited = async (options: ?PaginationParams): Promise<*> => { + fetchRecentlyUpdated = async (options: ?PaginationParams): Promise<*> => { const data = await this.fetchPage('list', options); - runInAction('DocumentsStore#fetchRecentlyEdited', () => { + runInAction('DocumentsStore#fetchRecentlyUpdated', () => { // $FlowFixMe - this.recentlyEditedIds.replace( - uniq(this.recentlyEditedIds.concat(map(data, 'id'))) + this.recentlyUpdatedIds.replace( + uniq(this.recentlyUpdatedIds.concat(map(data, 'id'))) ); }); return data; @@ -283,11 +281,11 @@ class DocumentsStore extends BaseStore { // Re-fetch dashboard content so that we don't show deleted documents this.on('collections.delete', () => { - this.fetchRecentlyEdited(); + this.fetchRecentlyUpdated(); this.fetchRecentlyViewed(); }); this.on('documents.delete', () => { - this.fetchRecentlyEdited(); + this.fetchRecentlyUpdated(); this.fetchRecentlyViewed(); }); }