Merge pull request #202 from jorilallo/dashboard-improves

Dashboard Improves
This commit is contained in:
Tom Moor
2017-09-09 07:44:14 -07:00
committed by GitHub
4 changed files with 25 additions and 13 deletions

View File

@@ -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() {

View File

@@ -38,14 +38,17 @@ class DocumentsStore extends BaseStore {
/* Computed */
@computed get recentlyViewed(): Array<Document> {
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<Document> {
// $FlowIssue
return this.data.values();
return _.take(this.data.values(), 5);
}
@computed get starred(): Array<Document> {
@@ -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<*> => {

View File

@@ -89,11 +89,11 @@ class ApiClient {
});
};
get = (path: string, data?: Object, options?: Object) => {
get = (path: string, data: ?Object, options?: Object) => {
return this.fetch(path, 'GET', data, options);
};
post = (path: string, data?: Object, options?: Object) => {
post = (path: string, data: ?Object, options?: Object) => {
return this.fetch(path, 'POST', data, options);
};

View File

@@ -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;