31 lines
800 B
JavaScript
31 lines
800 B
JavaScript
import { observable, action, runInAction } from 'mobx';
|
|
import { client, cacheResponse } from 'utils/ApiClient';
|
|
|
|
const store = new class DashboardStore {
|
|
@observable collections;
|
|
@observable pagination;
|
|
|
|
@observable isFetching = true;
|
|
|
|
/* Actions */
|
|
|
|
@action fetchCollections = async (teamId) => {
|
|
this.isFetching = true;
|
|
|
|
try {
|
|
const res = await client.post('/collections.list', { id: teamId });
|
|
const { data, pagination } = res;
|
|
runInAction('fetchCollections', () => {
|
|
this.collections = data;
|
|
this.pagination = pagination;
|
|
data.forEach((collection) => cacheResponse(collection.recentDocuments));
|
|
});
|
|
} catch (e) {
|
|
console.error("Something went wrong");
|
|
}
|
|
this.isFetching = false;
|
|
}
|
|
}();
|
|
|
|
export default store;
|