WIP
This commit is contained in:
parent
0684066d4a
commit
6c93bfda1d
|
@ -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() {
|
||||
|
|
|
@ -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<*> => {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Reference in New Issue