Setup for unauthenticated doc viewing

This commit is contained in:
Tom Moor
2018-05-12 21:01:17 -07:00
parent 3005da78e2
commit dded458582
8 changed files with 33 additions and 54 deletions

View File

@@ -1,29 +1,18 @@
// @flow
import {
observable,
action,
computed,
ObservableMap,
runInAction,
autorunAsync,
} from 'mobx';
import { observable, action, computed, ObservableMap, runInAction } from 'mobx';
import { client } from 'utils/ApiClient';
import _ from 'lodash';
import invariant from 'invariant';
import BaseStore from 'stores/BaseStore';
import stores from 'stores';
import Document from 'models/Document';
import ErrorsStore from 'stores/ErrorsStore';
import CacheStore from 'stores/CacheStore';
import UiStore from 'stores/UiStore';
import type { PaginationParams } from 'types';
const DOCUMENTS_CACHE_KEY = 'DOCUMENTS_CACHE_KEY';
export const DEFAULT_PAGINATION_LIMIT = 25;
type Options = {
cache: CacheStore,
ui: UiStore,
};
@@ -35,7 +24,6 @@ class DocumentsStore extends BaseStore {
@observable isFetching: boolean = false;
errors: ErrorsStore;
cache: CacheStore;
ui: UiStore;
/* Computed */
@@ -228,16 +216,9 @@ class DocumentsStore extends BaseStore {
constructor(options: Options) {
super();
this.errors = stores.errors;
this.cache = options.cache;
this.errors = options.errors;
this.ui = options.ui;
this.cache.getItem(DOCUMENTS_CACHE_KEY).then(data => {
if (data) {
data.forEach(document => this.add(new Document(document)));
}
});
this.on('documents.delete', (data: { id: string }) => {
this.remove(data.id);
});
@@ -254,15 +235,6 @@ class DocumentsStore extends BaseStore {
this.fetchRecentlyModified();
this.fetchRecentlyViewed();
});
autorunAsync('DocumentsStore.persists', () => {
if (this.data.size) {
this.cache.setItem(
DOCUMENTS_CACHE_KEY,
Array.from(this.data.values()).map(collection => collection.data)
);
}
});
}
}

View File

@@ -2,13 +2,16 @@
import AuthStore from './AuthStore';
import UiStore from './UiStore';
import ErrorsStore from './ErrorsStore';
import DocumentsStore from './DocumentsStore';
const ui = new UiStore();
const errors = new ErrorsStore();
const stores = {
user: null, // Including for Layout
auth: new AuthStore(),
ui: new UiStore(),
errors: new ErrorsStore(),
ui,
errors,
documents: new DocumentsStore({ ui, errors }),
};
window.stores = stores;
export default stores;