Collection model

This commit is contained in:
Jori Lallo
2017-05-23 00:45:15 -07:00
parent 07ff5b6ae5
commit 6b566a568f
6 changed files with 116 additions and 16 deletions

View File

@@ -2,7 +2,7 @@
import { observable, action, computed } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { Collection } from 'types';
import Collection from 'models/Collection';
const store = new class AtlasStore {
@observable collection: ?(Collection & { recentDocuments?: Object[] });
@@ -25,7 +25,7 @@ const store = new class AtlasStore {
const res = await client.get('/collections.info', { id });
invariant(res && res.data, 'Data should be available');
const { data } = res;
this.collection = data;
this.collection = new Collection(data);
successCallback(data);
} catch (e) {
console.error('Something went wrong');

View File

@@ -2,7 +2,8 @@
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { Pagination, Collection } from 'types';
import type { Pagination } from 'types';
import Collection from 'models/Collection';
type Options = {
team: Object,
@@ -30,7 +31,7 @@ class DashboardStore {
);
const { data, pagination } = res;
runInAction('fetchCollections', () => {
this.collections = data;
this.collections = data.map(collection => new Collection(collection));
this.pagination = pagination;
});
} catch (e) {