From 6eecd830dbc717be185cf25291e459f8edca4a97 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 25 Jun 2017 14:36:58 -0700 Subject: [PATCH] Cleanup and show active collection in the sidebar --- frontend/scenes/Document/Document.scss | 11 ----- frontend/scenes/Document/DocumentStore.js | 53 ++++++++++------------- frontend/stores/index.js | 1 + 3 files changed, 24 insertions(+), 41 deletions(-) delete mode 100644 frontend/scenes/Document/Document.scss diff --git a/frontend/scenes/Document/Document.scss b/frontend/scenes/Document/Document.scss deleted file mode 100644 index c31a12f3f..000000000 --- a/frontend/scenes/Document/Document.scss +++ /dev/null @@ -1,11 +0,0 @@ -@import '~styles/constants.scss'; - -.container { - display: flex; - position: fixed; - justify-content: center; - top: $headerHeight; - bottom: 0; - left: 0; - right: 0; -} diff --git a/frontend/scenes/Document/DocumentStore.js b/frontend/scenes/Document/DocumentStore.js index 1a146e412..1772e5dd3 100644 --- a/frontend/scenes/Document/DocumentStore.js +++ b/frontend/scenes/Document/DocumentStore.js @@ -5,6 +5,7 @@ import invariant from 'invariant'; import { client } from 'utils/ApiClient'; import emojify from 'utils/emojify'; import type { Document, NavigationNode } from 'types'; +import UiStore from 'stores/UiStore'; type SaveProps = { redirect?: boolean }; @@ -24,6 +25,7 @@ const parseHeader = text => { type Options = { history: Object, + ui: UiStore, }; class DocumentStore { @@ -42,6 +44,7 @@ class DocumentStore { @observable isUploading: boolean = false; history: Object; + ui: UiStore; /* Computed */ @@ -108,18 +111,15 @@ class DocumentStore { this.isFetching = true; try { - const res = await client.get( - '/documents.info', - { - id: this.documentId, - }, - { cache: true } - ); + const res = await client.get('/documents.info', { + id: this.documentId, + }); invariant(res && res.data, 'Data should be available'); if (this.newChildDocument) { this.parentDocument = res.data; } else { this.document = res.data; + this.ui.setActiveCollection(this.document.collection.id); } } catch (e) { console.error('Something went wrong'); @@ -133,20 +133,16 @@ class DocumentStore { this.isSaving = true; try { - const res = await client.post( - '/documents.create', - { - parentDocument: get(this.parentDocument, 'id'), - collection: get( - this.parentDocument, - 'collection.id', - this.collectionId - ), - title: get(this.document, 'title', 'Untitled document'), - text: get(this.document, 'text'), - }, - { cache: true } - ); + const res = await client.post('/documents.create', { + parentDocument: get(this.parentDocument, 'id'), + collection: get( + this.parentDocument, + 'collection.id', + this.collectionId + ), + title: get(this.document, 'title', 'Untitled document'), + text: get(this.document, 'text'), + }); invariant(res && res.data, 'Data should be available'); const { url } = res.data; @@ -164,15 +160,11 @@ class DocumentStore { this.isSaving = true; try { - const res = await client.post( - '/documents.update', - { - id: this.documentId, - title: get(this.document, 'title', 'Untitled document'), - text: get(this.document, 'text'), - }, - { cache: true } - ); + const res = await client.post('/documents.update', { + id: this.documentId, + title: get(this.document, 'title', 'Untitled document'), + text: get(this.document, 'text'), + }); invariant(res && res.data, 'Data should be available'); const { url } = res.data; @@ -210,6 +202,7 @@ class DocumentStore { constructor(options: Options) { this.history = options.history; + this.ui = options.ui; } } diff --git a/frontend/stores/index.js b/frontend/stores/index.js index 70eb0853d..ccfaa9c8c 100644 --- a/frontend/stores/index.js +++ b/frontend/stores/index.js @@ -9,5 +9,6 @@ const stores = { ui: new UiStore(), errors: new ErrorsStore(), }; +window.stores = stores; export default stores;