Pagination of edited / viewed responses
This commit is contained in:
Tom Moor
2018-08-11 00:46:10 -07:00
parent 6b2211f135
commit 63f6d61ac0
3 changed files with 20 additions and 19 deletions

View File

@@ -59,6 +59,7 @@ class Slack extends React.Component<Props> {
<SlackButton <SlackButton
scopes={['commands', 'links:read', 'links:write']} scopes={['commands', 'links:read', 'links:write']}
redirectUri={`${BASE_URL}/auth/slack.commands`} redirectUri={`${BASE_URL}/auth/slack.commands`}
state=""
/> />
)} )}
</p> </p>

View File

@@ -1,7 +1,7 @@
// @flow // @flow
import { observable, action, computed, ObservableMap, runInAction } from 'mobx'; import { observable, action, computed, ObservableMap, runInAction } from 'mobx';
import { client } from 'utils/ApiClient'; import { client } from 'utils/ApiClient';
import _ from 'lodash'; import { map, find, orderBy, filter, uniq } from 'lodash';
import invariant from 'invariant'; import invariant from 'invariant';
import BaseStore from 'stores/BaseStore'; import BaseStore from 'stores/BaseStore';
@@ -50,26 +50,23 @@ class DocumentsStore extends BaseStore {
} }
createdByUser(userId: string): Document[] { createdByUser(userId: string): Document[] {
return _.orderBy( return orderBy(
_.filter( filter(this.data.values(), document => document.createdBy.id === userId),
this.data.values(),
document => document.createdBy.id === userId
),
'updatedAt', 'updatedAt',
'desc' 'desc'
); );
} }
pinnedInCollection(collectionId: string): Document[] { pinnedInCollection(collectionId: string): Document[] {
return _.filter( return filter(
this.recentlyEditedInCollection(collectionId), this.recentlyEditedInCollection(collectionId),
document => document.pinned document => document.pinned
); );
} }
recentlyEditedInCollection(collectionId: string): Document[] { recentlyEditedInCollection(collectionId: string): Document[] {
return _.orderBy( return orderBy(
_.filter( filter(
this.data.values(), this.data.values(),
document => document =>
document.collectionId === collectionId && !!document.publishedAt document.collectionId === collectionId && !!document.publishedAt
@@ -81,13 +78,13 @@ class DocumentsStore extends BaseStore {
@computed @computed
get starred(): Document[] { get starred(): Document[] {
return _.filter(this.data.values(), 'starred'); return filter(this.data.values(), 'starred');
} }
@computed @computed
get drafts(): Document[] { get drafts(): Document[] {
return _.filter( return filter(
_.orderBy(this.data.values(), 'updatedAt', 'desc'), orderBy(this.data.values(), 'updatedAt', 'desc'),
doc => !doc.publishedAt doc => !doc.publishedAt
); );
} }
@@ -131,7 +128,9 @@ class DocumentsStore extends BaseStore {
const data = await this.fetchPage('list', options); const data = await this.fetchPage('list', options);
runInAction('DocumentsStore#fetchRecentlyEdited', () => { runInAction('DocumentsStore#fetchRecentlyEdited', () => {
this.recentlyEditedIds = _.map(data, 'id'); this.recentlyEditedIds = uniq(
map(data, 'id').concat(this.recentlyEditedIds)
);
}); });
return data; return data;
}; };
@@ -141,7 +140,9 @@ class DocumentsStore extends BaseStore {
const data = await this.fetchPage('viewed', options); const data = await this.fetchPage('viewed', options);
runInAction('DocumentsStore#fetchRecentlyViewed', () => { runInAction('DocumentsStore#fetchRecentlyViewed', () => {
this.recentlyViewedIds = _.map(data, 'id'); this.recentlyViewedIds = uniq(
map(data, 'id').concat(this.recentlyViewedIds)
);
}); });
return data; return data;
}; };
@@ -258,7 +259,7 @@ class DocumentsStore extends BaseStore {
* Match documents by the url ID as the title slug can change * Match documents by the url ID as the title slug can change
*/ */
getByUrl = (url: string): ?Document => { 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) { constructor(options: Options) {

View File

@@ -1,6 +1,5 @@
// @flow // @flow
export function toCodePoint(unicodeSurrogates: string, sep: ?string) {
export function toCodePoint(unicodeSurrogates, sep) {
var r = [], var r = [],
c = 0, c = 0,
p = 0, p = 0,
@@ -19,6 +18,6 @@ export function toCodePoint(unicodeSurrogates, sep) {
return r.join(sep || '-'); return r.join(sep || '-');
} }
export function emojiToUrl(string: text) { export function emojiToUrl(text: string) {
return `https://twemoji.maxcdn.com/2/72x72/${toCodePoint(string)}.png`; return `https://twemoji.maxcdn.com/2/72x72/${toCodePoint(text)}.png`;
} }