From 63f6d61ac02cda6bf8b3390f4ab7bfa568e2e1be Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 11 Aug 2018 00:46:10 -0700 Subject: [PATCH] Linting Pagination of edited / viewed responses --- app/scenes/Settings/Slack.js | 1 + app/stores/DocumentsStore.js | 31 ++++++++++++++++--------------- app/utils/emoji.js | 7 +++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/scenes/Settings/Slack.js b/app/scenes/Settings/Slack.js index 944678ced..c122cbd5f 100644 --- a/app/scenes/Settings/Slack.js +++ b/app/scenes/Settings/Slack.js @@ -59,6 +59,7 @@ class Slack extends React.Component { )}

diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js index eb940512b..2e639ea65 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 _ from 'lodash'; +import { map, find, orderBy, filter, uniq } from 'lodash'; import invariant from 'invariant'; import BaseStore from 'stores/BaseStore'; @@ -50,26 +50,23 @@ class DocumentsStore extends BaseStore { } createdByUser(userId: string): Document[] { - return _.orderBy( - _.filter( - this.data.values(), - document => document.createdBy.id === userId - ), + return orderBy( + filter(this.data.values(), document => document.createdBy.id === userId), 'updatedAt', 'desc' ); } pinnedInCollection(collectionId: string): Document[] { - return _.filter( + return filter( this.recentlyEditedInCollection(collectionId), document => document.pinned ); } recentlyEditedInCollection(collectionId: string): Document[] { - return _.orderBy( - _.filter( + return orderBy( + filter( this.data.values(), document => document.collectionId === collectionId && !!document.publishedAt @@ -81,13 +78,13 @@ class DocumentsStore extends BaseStore { @computed get starred(): Document[] { - return _.filter(this.data.values(), 'starred'); + return filter(this.data.values(), 'starred'); } @computed get drafts(): Document[] { - return _.filter( - _.orderBy(this.data.values(), 'updatedAt', 'desc'), + return filter( + orderBy(this.data.values(), 'updatedAt', 'desc'), doc => !doc.publishedAt ); } @@ -131,7 +128,9 @@ class DocumentsStore extends BaseStore { const data = await this.fetchPage('list', options); runInAction('DocumentsStore#fetchRecentlyEdited', () => { - this.recentlyEditedIds = _.map(data, 'id'); + this.recentlyEditedIds = uniq( + map(data, 'id').concat(this.recentlyEditedIds) + ); }); return data; }; @@ -141,7 +140,9 @@ class DocumentsStore extends BaseStore { const data = await this.fetchPage('viewed', options); runInAction('DocumentsStore#fetchRecentlyViewed', () => { - this.recentlyViewedIds = _.map(data, 'id'); + this.recentlyViewedIds = uniq( + map(data, 'id').concat(this.recentlyViewedIds) + ); }); return data; }; @@ -258,7 +259,7 @@ class DocumentsStore extends BaseStore { * Match documents by the url ID as the title slug can change */ getByUrl = (url: string): ?Document => { - return _.find(this.data.values(), doc => url.endsWith(doc.urlId)); + return find(this.data.values(), doc => url.endsWith(doc.urlId)); }; constructor(options: Options) { diff --git a/app/utils/emoji.js b/app/utils/emoji.js index 818991869..342e8af92 100644 --- a/app/utils/emoji.js +++ b/app/utils/emoji.js @@ -1,6 +1,5 @@ // @flow - -export function toCodePoint(unicodeSurrogates, sep) { +export function toCodePoint(unicodeSurrogates: string, sep: ?string) { var r = [], c = 0, p = 0, @@ -19,6 +18,6 @@ export function toCodePoint(unicodeSurrogates, sep) { return r.join(sep || '-'); } -export function emojiToUrl(string: text) { - return `https://twemoji.maxcdn.com/2/72x72/${toCodePoint(string)}.png`; +export function emojiToUrl(text: string) { + return `https://twemoji.maxcdn.com/2/72x72/${toCodePoint(text)}.png`; }