diff --git a/frontend/scenes/Dashboard/Dashboard.js b/frontend/scenes/Dashboard/Dashboard.js index da95a0f2..f8adf4b0 100644 --- a/frontend/scenes/Dashboard/Dashboard.js +++ b/frontend/scenes/Dashboard/Dashboard.js @@ -28,8 +28,8 @@ type Props = { props: Props; componentDidMount() { - this.props.documents.fetchAll(); - this.props.documents.fetchRecentlyViewed(); + this.props.documents.fetchRecentlyModified({ limit: 5 }); + this.props.documents.fetchRecentlyViewed({ limit: 5 }); } get showPlaceholder() { diff --git a/frontend/stores/DocumentsStore.js b/frontend/stores/DocumentsStore.js index 3d839a1c..444a47bb 100644 --- a/frontend/stores/DocumentsStore.js +++ b/frontend/stores/DocumentsStore.js @@ -38,14 +38,17 @@ class DocumentsStore extends BaseStore { /* Computed */ @computed get recentlyViewed(): Array { - return _.filter(this.data.values(), ({ id }) => - this.recentlyViewedIds.includes(id) + return _.take( + _.filter(this.data.values(), ({ id }) => + this.recentlyViewedIds.includes(id) + ), + 5 ); } @computed get recentlyEdited(): Array { // $FlowIssue - return this.data.values(); + return _.take(this.data.values(), 5); } @computed get starred(): Array { @@ -60,11 +63,14 @@ class DocumentsStore extends BaseStore { /* Actions */ - @action fetchAll = async (request: string = 'list'): Promise<*> => { + @action fetchAll = async ( + request: string = 'list', + options: ?Object + ): Promise<*> => { this.isFetching = true; try { - const res = await client.post(`/documents.${request}`); + const res = await client.post(`/documents.${request}`, options); invariant(res && res.data, 'Document list not available'); const { data } = res; runInAction('DocumentsStore#fetchAll', () => { @@ -81,12 +87,17 @@ class DocumentsStore extends BaseStore { } }; - @action fetchRecentlyViewed = async (): Promise<*> => { - const data = await this.fetchAll('viewed'); + @action fetchRecentlyModified = async (options: ?Object): Promise<*> => { + return this.fetchAll('list', options); + }; + + @action fetchRecentlyViewed = async (options: ?Object): Promise<*> => { + const data = await this.fetchAll('viewed', options); runInAction('DocumentsStore#fetchRecentlyViewed', () => { this.recentlyViewedIds = _.map(data, 'id'); }); + return data; }; @action fetchStarred = async (): Promise<*> => { diff --git a/server/api/middlewares/pagination.js b/server/api/middlewares/pagination.js index 57ebf03a..d0e94048 100644 --- a/server/api/middlewares/pagination.js +++ b/server/api/middlewares/pagination.js @@ -10,8 +10,9 @@ export default function pagination(options) { }; let query = ctx.request.query; - let limit = parseInt(query.limit, 10); - let offset = parseInt(query.offset, 10); + let body = ctx.request.body; + let limit = parseInt(query.limit || body.limit, 10); + let offset = parseInt(query.offset || body.offset, 10); limit = isNaN(limit) ? opts.defaultLimit : limit; offset = isNaN(offset) ? 0 : offset;