diff --git a/app/index.js b/app/index.js
index d64a6db5b..394ee5be4 100644
--- a/app/index.js
+++ b/app/index.js
@@ -68,11 +68,7 @@ if (element) {
/>
-
+
diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js
index f0fb6fccb..658585461 100644
--- a/app/scenes/Document/Document.js
+++ b/app/scenes/Document/Document.js
@@ -24,6 +24,7 @@ import Document from 'models/Document';
import Actions from './components/Actions';
import DocumentMove from './components/DocumentMove';
import UiStore from 'stores/UiStore';
+import AuthStore from 'stores/AuthStore';
import DocumentsStore from 'stores/DocumentsStore';
import LoadingPlaceholder from 'components/LoadingPlaceholder';
import LoadingIndicator from 'components/LoadingIndicator';
@@ -43,6 +44,7 @@ type Props = {
location: Location,
documents: DocumentsStore,
newDocument?: boolean,
+ auth: AuthStore,
ui: UiStore,
};
@@ -52,6 +54,7 @@ class DocumentScene extends React.Component {
@observable editorComponent;
@observable editCache: ?string;
+ @observable document: ?Document;
@observable newDocument: ?Document;
@observable isLoading = false;
@observable isSaving = false;
@@ -87,7 +90,7 @@ class DocumentScene extends React.Component {
loadDocument = async props => {
if (props.newDocument) {
- const newDocument = new Document({
+ this.document = new Document({
collection: { id: props.match.params.id },
parentDocument: new URLSearchParams(props.location.search).get(
'parentDocument'
@@ -95,32 +98,30 @@ class DocumentScene extends React.Component {
title: '',
text: '',
});
- this.newDocument = newDocument;
} else {
- let document = this.getDocument(props.match.params.documentSlug);
+ this.document = await this.props.documents.fetch(
+ props.match.params.documentSlug,
+ { shareId: props.match.params.shareId }
+ );
- if (document) {
- this.props.documents.fetch(props.match.params.documentSlug);
- this.props.ui.setActiveDocument(document);
- } else {
- document = await this.props.documents.fetch(
- props.match.params.documentSlug
- );
- }
+ const document = this.document;
if (document) {
this.props.ui.setActiveDocument(document);
// Cache data if user enters edit mode and cancels
this.editCache = document.text;
- if (!this.isEditing && document.publishedAt) {
- document.view();
- }
- // Update url to match the current one
- this.props.history.replace(
- updateDocumentUrl(props.match.url, document.url)
- );
+ if (this.props.auth.user) {
+ if (!this.isEditing && document.publishedAt) {
+ document.view();
+ }
+
+ // Update url to match the current one
+ this.props.history.replace(
+ updateDocumentUrl(props.match.url, document.url)
+ );
+ }
} else {
// Render 404 with search
this.notFound = true;
@@ -134,22 +135,14 @@ class DocumentScene extends React.Component {
};
get isEditing() {
+ const document = this.document;
+
return !!(
- this.props.match.path === matchDocumentEdit || this.props.newDocument
+ this.props.match.path === matchDocumentEdit ||
+ (document && !document.id)
);
}
- getDocument(documentSlug: ?string) {
- if (this.newDocument) return this.newDocument;
- return this.props.documents.getByUrl(
- `/doc/${documentSlug || this.props.match.params.documentSlug}`
- );
- }
-
- get document() {
- return this.getDocument();
- }
-
handleCloseMoveModal = () => (this.moveModalOpen = false);
handleOpenMoveModal = () => (this.moveModalOpen = true);
@@ -159,6 +152,7 @@ class DocumentScene extends React.Component {
let document = this.document;
if (!document || !document.allowSave) return;
+ let isNew = !document.id;
this.editCache = null;
this.isSaving = true;
this.isPublishing = !!options.publish;
@@ -169,7 +163,7 @@ class DocumentScene extends React.Component {
if (options.done) {
this.props.history.push(document.url);
this.props.ui.setActiveDocument(document);
- } else if (this.props.newDocument) {
+ } else if (isNew) {
this.props.history.push(documentEditUrl(document));
this.props.ui.setActiveDocument(document);
}
@@ -246,7 +240,7 @@ class DocumentScene extends React.Component {
}
return (
-
+
{isMoving && document && }
{titleText && }
{(this.isLoading || this.isSaving) && }
@@ -319,4 +313,4 @@ const LoadingState = styled(LoadingPlaceholder)`
margin: 90px 0;
`;
-export default withRouter(inject('ui', 'user', 'documents')(DocumentScene));
+export default withRouter(inject('ui', 'auth', 'documents')(DocumentScene));
diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js
index 7aafcc14d..08ce80044 100644
--- a/app/stores/DocumentsStore.js
+++ b/app/stores/DocumentsStore.js
@@ -182,6 +182,9 @@ class DocumentsStore extends BaseStore {
if (!options.prefetch) this.isFetching = true;
try {
+ const doc = this.getById(id) || this.getByUrl(id);
+ if (doc) return doc;
+
const res = await client.post('/documents.info', {
id,
shareId: options.shareId,
diff --git a/server/api/documents.js b/server/api/documents.js
index 25e1c8769..6219c36f3 100644
--- a/server/api/documents.js
+++ b/server/api/documents.js
@@ -172,6 +172,8 @@ router.post('documents.info', auth({ required: false }), async ctx => {
},
],
});
+
+ // TODO: REMOVE COLLECTION AND COLLABORATOR INFO
document = share.document;
} else {
document = await Document.findById(id);