Cleanup and show active collection in the sidebar

This commit is contained in:
Jori Lallo
2017-06-25 14:36:58 -07:00
parent c0f971fdd0
commit 6eecd830db
3 changed files with 24 additions and 41 deletions

View File

@@ -1,11 +0,0 @@
@import '~styles/constants.scss';
.container {
display: flex;
position: fixed;
justify-content: center;
top: $headerHeight;
bottom: 0;
left: 0;
right: 0;
}

View File

@@ -5,6 +5,7 @@ import invariant from 'invariant';
import { client } from 'utils/ApiClient'; import { client } from 'utils/ApiClient';
import emojify from 'utils/emojify'; import emojify from 'utils/emojify';
import type { Document, NavigationNode } from 'types'; import type { Document, NavigationNode } from 'types';
import UiStore from 'stores/UiStore';
type SaveProps = { redirect?: boolean }; type SaveProps = { redirect?: boolean };
@@ -24,6 +25,7 @@ const parseHeader = text => {
type Options = { type Options = {
history: Object, history: Object,
ui: UiStore,
}; };
class DocumentStore { class DocumentStore {
@@ -42,6 +44,7 @@ class DocumentStore {
@observable isUploading: boolean = false; @observable isUploading: boolean = false;
history: Object; history: Object;
ui: UiStore;
/* Computed */ /* Computed */
@@ -108,18 +111,15 @@ class DocumentStore {
this.isFetching = true; this.isFetching = true;
try { try {
const res = await client.get( const res = await client.get('/documents.info', {
'/documents.info', id: this.documentId,
{ });
id: this.documentId,
},
{ cache: true }
);
invariant(res && res.data, 'Data should be available'); invariant(res && res.data, 'Data should be available');
if (this.newChildDocument) { if (this.newChildDocument) {
this.parentDocument = res.data; this.parentDocument = res.data;
} else { } else {
this.document = res.data; this.document = res.data;
this.ui.setActiveCollection(this.document.collection.id);
} }
} catch (e) { } catch (e) {
console.error('Something went wrong'); console.error('Something went wrong');
@@ -133,20 +133,16 @@ class DocumentStore {
this.isSaving = true; this.isSaving = true;
try { try {
const res = await client.post( const res = await client.post('/documents.create', {
'/documents.create', parentDocument: get(this.parentDocument, 'id'),
{ collection: get(
parentDocument: get(this.parentDocument, 'id'), this.parentDocument,
collection: get( 'collection.id',
this.parentDocument, this.collectionId
'collection.id', ),
this.collectionId title: get(this.document, 'title', 'Untitled document'),
), text: get(this.document, 'text'),
title: get(this.document, 'title', 'Untitled document'), });
text: get(this.document, 'text'),
},
{ cache: true }
);
invariant(res && res.data, 'Data should be available'); invariant(res && res.data, 'Data should be available');
const { url } = res.data; const { url } = res.data;
@@ -164,15 +160,11 @@ class DocumentStore {
this.isSaving = true; this.isSaving = true;
try { try {
const res = await client.post( const res = await client.post('/documents.update', {
'/documents.update', id: this.documentId,
{ title: get(this.document, 'title', 'Untitled document'),
id: this.documentId, text: get(this.document, 'text'),
title: get(this.document, 'title', 'Untitled document'), });
text: get(this.document, 'text'),
},
{ cache: true }
);
invariant(res && res.data, 'Data should be available'); invariant(res && res.data, 'Data should be available');
const { url } = res.data; const { url } = res.data;
@@ -210,6 +202,7 @@ class DocumentStore {
constructor(options: Options) { constructor(options: Options) {
this.history = options.history; this.history = options.history;
this.ui = options.ui;
} }
} }

View File

@@ -9,5 +9,6 @@ const stores = {
ui: new UiStore(), ui: new UiStore(),
errors: new ErrorsStore(), errors: new ErrorsStore(),
}; };
window.stores = stores;
export default stores; export default stores;