diff --git a/app/components/Auth.js b/app/components/Auth.js index b3cd00296..6a9d3f867 100644 --- a/app/components/Auth.js +++ b/app/components/Auth.js @@ -4,7 +4,6 @@ import { Provider } from 'mobx-react'; import stores from 'stores'; import ApiKeysStore from 'stores/ApiKeysStore'; import UsersStore from 'stores/UsersStore'; -import DocumentsStore from 'stores/DocumentsStore'; import CollectionsStore from 'stores/CollectionsStore'; import IntegrationsStore from 'stores/IntegrationsStore'; import CacheStore from 'stores/CacheStore'; @@ -27,10 +26,6 @@ const Auth = ({ children }: Props) => { integrations: new IntegrationsStore(), apiKeys: new ApiKeysStore(), users: new UsersStore(), - documents: new DocumentsStore({ - ui: stores.ui, - cache, - }), collections: new CollectionsStore({ ui: stores.ui, teamId: team.id, diff --git a/app/components/DocumentPreview/DocumentPreview.js b/app/components/DocumentPreview/DocumentPreview.js index d6026c353..e5c303e7d 100644 --- a/app/components/DocumentPreview/DocumentPreview.js +++ b/app/components/DocumentPreview/DocumentPreview.js @@ -112,7 +112,14 @@ class DocumentPreview extends React.Component { } = this.props; return ( - + {document.publishedAt && ( diff --git a/app/components/Sidebar/components/DocumentLink.js b/app/components/Sidebar/components/DocumentLink.js index dd47ae7e7..43bd9eb24 100644 --- a/app/components/Sidebar/components/DocumentLink.js +++ b/app/components/Sidebar/components/DocumentLink.js @@ -60,7 +60,10 @@ class DocumentLink extends React.Component { activeClassName="activeDropZone" > ) => *, children?: React.Node, icon?: React.Node, @@ -59,7 +59,6 @@ type Props = { active?: boolean, }; -@withRouter @observer class SidebarLink extends React.Component { @observable expanded: boolean = false; @@ -158,4 +157,4 @@ const Content = styled.div` width: 100%; `; -export default SidebarLink; +export default withRouter(SidebarLink); diff --git a/app/index.js b/app/index.js index bb84a01c9..d64a6db5b 100644 --- a/app/index.js +++ b/app/index.js @@ -68,6 +68,11 @@ if (element) { /> + diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index 3d952d64a..f0fb6fccb 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -1,6 +1,5 @@ // @flow import * as React from 'react'; -import get from 'lodash/get'; import debounce from 'lodash/debounce'; import styled from 'styled-components'; import breakpoint from 'styled-components-breakpoint'; @@ -26,7 +25,6 @@ import Actions from './components/Actions'; import DocumentMove from './components/DocumentMove'; import UiStore from 'stores/UiStore'; import DocumentsStore from 'stores/DocumentsStore'; -import CollectionsStore from 'stores/CollectionsStore'; import LoadingPlaceholder from 'components/LoadingPlaceholder'; import LoadingIndicator from 'components/LoadingIndicator'; import CenteredContent from 'components/CenteredContent'; @@ -44,7 +42,6 @@ type Props = { history: Object, location: Location, documents: DocumentsStore, - collections: CollectionsStore, newDocument?: boolean, ui: UiStore, }; @@ -237,19 +234,19 @@ class DocumentScene extends React.Component { }; render() { + const { location, match } = this.props; const Editor = this.editorComponent; - const isMoving = this.props.match.path === matchDocumentMove; + const isMoving = match.path === matchDocumentMove; const document = this.document; - const titleText = - get(document, 'title', '') || - this.props.collections.titleForDocument(this.props.location.pathname); + const titleFromState = location.state ? location.state.title : ''; + const titleText = document ? document.title : titleFromState; if (this.notFound) { return ; } return ( - + {isMoving && document && } {titleText && } {(this.isLoading || this.isSaving) && } @@ -322,6 +319,4 @@ const LoadingState = styled(LoadingPlaceholder)` margin: 90px 0; `; -export default withRouter( - inject('ui', 'user', 'documents', 'collections')(DocumentScene) -); +export default withRouter(inject('ui', 'user', 'documents')(DocumentScene)); diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js index d161deaff..8ffba9c54 100644 --- a/app/stores/DocumentsStore.js +++ b/app/stores/DocumentsStore.js @@ -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) - ); - } - }); } } diff --git a/app/stores/index.js b/app/stores/index.js index ccfaa9c8c..f175941d5 100644 --- a/app/stores/index.js +++ b/app/stores/index.js @@ -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;