WIP
This commit is contained in:
@ -28,8 +28,8 @@ type Props = {
|
|||||||
props: Props;
|
props: Props;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.documents.fetchAll();
|
this.props.documents.fetchRecentlyModified({ limit: 5 });
|
||||||
this.props.documents.fetchRecentlyViewed();
|
this.props.documents.fetchRecentlyViewed({ limit: 5 });
|
||||||
}
|
}
|
||||||
|
|
||||||
get showPlaceholder() {
|
get showPlaceholder() {
|
||||||
|
@ -38,14 +38,17 @@ class DocumentsStore extends BaseStore {
|
|||||||
/* Computed */
|
/* Computed */
|
||||||
|
|
||||||
@computed get recentlyViewed(): Array<Document> {
|
@computed get recentlyViewed(): Array<Document> {
|
||||||
return _.filter(this.data.values(), ({ id }) =>
|
return _.take(
|
||||||
|
_.filter(this.data.values(), ({ id }) =>
|
||||||
this.recentlyViewedIds.includes(id)
|
this.recentlyViewedIds.includes(id)
|
||||||
|
),
|
||||||
|
5
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get recentlyEdited(): Array<Document> {
|
@computed get recentlyEdited(): Array<Document> {
|
||||||
// $FlowIssue
|
// $FlowIssue
|
||||||
return this.data.values();
|
return _.take(this.data.values(), 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get starred(): Array<Document> {
|
@computed get starred(): Array<Document> {
|
||||||
@ -60,11 +63,14 @@ class DocumentsStore extends BaseStore {
|
|||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
|
|
||||||
@action fetchAll = async (request: string = 'list'): Promise<*> => {
|
@action fetchAll = async (
|
||||||
|
request: string = 'list',
|
||||||
|
options: ?Object
|
||||||
|
): Promise<*> => {
|
||||||
this.isFetching = true;
|
this.isFetching = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await client.post(`/documents.${request}`);
|
const res = await client.post(`/documents.${request}`, options);
|
||||||
invariant(res && res.data, 'Document list not available');
|
invariant(res && res.data, 'Document list not available');
|
||||||
const { data } = res;
|
const { data } = res;
|
||||||
runInAction('DocumentsStore#fetchAll', () => {
|
runInAction('DocumentsStore#fetchAll', () => {
|
||||||
@ -81,12 +87,17 @@ class DocumentsStore extends BaseStore {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@action fetchRecentlyViewed = async (): Promise<*> => {
|
@action fetchRecentlyModified = async (options: ?Object): Promise<*> => {
|
||||||
const data = await this.fetchAll('viewed');
|
return this.fetchAll('list', options);
|
||||||
|
};
|
||||||
|
|
||||||
|
@action fetchRecentlyViewed = async (options: ?Object): Promise<*> => {
|
||||||
|
const data = await this.fetchAll('viewed', options);
|
||||||
|
|
||||||
runInAction('DocumentsStore#fetchRecentlyViewed', () => {
|
runInAction('DocumentsStore#fetchRecentlyViewed', () => {
|
||||||
this.recentlyViewedIds = _.map(data, 'id');
|
this.recentlyViewedIds = _.map(data, 'id');
|
||||||
});
|
});
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@action fetchStarred = async (): Promise<*> => {
|
@action fetchStarred = async (): Promise<*> => {
|
||||||
|
@ -10,8 +10,9 @@ export default function pagination(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let query = ctx.request.query;
|
let query = ctx.request.query;
|
||||||
let limit = parseInt(query.limit, 10);
|
let body = ctx.request.body;
|
||||||
let offset = parseInt(query.offset, 10);
|
let limit = parseInt(query.limit || body.limit, 10);
|
||||||
|
let offset = parseInt(query.offset || body.offset, 10);
|
||||||
limit = isNaN(limit) ? opts.defaultLimit : limit;
|
limit = isNaN(limit) ? opts.defaultLimit : limit;
|
||||||
offset = isNaN(offset) ? 0 : offset;
|
offset = isNaN(offset) ? 0 : offset;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user