Setup for unauthenticated doc viewing
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user