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/DashboardStore.js
2017-05-11 17:23:56 -07:00

50 lines
1.1 KiB
JavaScript

// @flow
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { Pagination, Collection } from 'types';
type Options = {
team: Object,
router: Object,
};
class DashboardStore {
team: Object;
router: Object;
@observable collections: Array<Collection>;
@observable pagination: Pagination;
@observable isFetching: boolean = true;
/* Actions */
@action fetchCollections = async () => {
this.isFetching = true;
try {
const res = await client.post('/collections.list', { id: this.team.id });
invariant(
res && res.data && res.pagination,
'API response should be available'
);
const { data, pagination } = res;
runInAction('fetchCollections', () => {
this.collections = data;
this.pagination = pagination;
});
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
constructor(options: Options) {
this.team = options.team;
this.router = options.router;
this.fetchCollections();
}
}
export default DashboardStore;