Share links list WIP

This commit is contained in:
Tom Moor
2018-05-22 23:01:49 -07:00
parent b40b77b228
commit d93815ca0a
13 changed files with 224 additions and 11 deletions

43
app/stores/SharesStore.js Normal file
View File

@@ -0,0 +1,43 @@
// @flow
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { Share, PaginationParams } from 'types';
class SharesStore {
@observable data: Share[] = [];
@observable isFetching: boolean = false;
@observable isSaving: boolean = false;
@action
fetchPage = async (options: ?PaginationParams): Promise<*> => {
this.isFetching = true;
try {
const res = await client.post('/shares.list', options);
invariant(res && res.data, 'Data should be available');
const { data } = res;
runInAction('fetchShares', () => {
this.data = data;
});
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
@action
deleteShare = async (id: string) => {
try {
await client.post('/shares.delete', { id });
runInAction('deleteShare', () => {
this.fetchPage();
});
} catch (e) {
console.error('Something went wrong');
}
};
}
export default SharesStore;

View File

@@ -3,6 +3,7 @@ import AuthStore from './AuthStore';
import UiStore from './UiStore';
import ErrorsStore from './ErrorsStore';
import DocumentsStore from './DocumentsStore';
import SharesStore from './SharesStore';
const ui = new UiStore();
const errors = new ErrorsStore();
@@ -12,6 +13,7 @@ const stores = {
ui,
errors,
documents: new DocumentsStore({ ui, errors }),
shares: new SharesStore(),
};
export default stores;