This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/frontend/scenes/Dashboard/RecentDocumentsStore.js
2017-06-25 20:32:05 -07:00

30 lines
766 B
JavaScript

// @flow
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { Document } from 'types';
class RecentDocumentsStore {
@observable documents: Array<Document> = [];
@observable isFetching = false;
@action fetchDocuments = async () => {
this.isFetching = true;
try {
const res = await client.get('/documents.viewed');
invariant(res && res.data, 'res or res.data missing');
const { data } = res;
runInAction('update state after fetching data', () => {
this.documents = data;
});
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
}
export default RecentDocumentsStore;