From 39c6ba63f5f17c265b0f50248efaf02d367a53d5 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 10 Sep 2017 12:58:48 -0400 Subject: [PATCH 1/3] Render 404 with search if user tries to load unknown document --- frontend/scenes/Document/Document.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index 531d289fd..b125a9e8c 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -20,6 +20,7 @@ import LoadingIndicator from 'components/LoadingIndicator'; import Collaborators from 'components/Collaborators'; import CenteredContent from 'components/CenteredContent'; import PageTitle from 'components/PageTitle'; +import Search from 'scenes/Search'; const DISCARD_CHANGES = ` You have unsaved changes. @@ -47,6 +48,7 @@ type Props = { isSaving: false, newDocument: undefined, showAsSaved: false, + notFound: false, }; componentDidMount() { @@ -58,6 +60,7 @@ type Props = { nextProps.match.params.documentSlug !== this.props.match.params.documentSlug ) { + this.setState({ notFound: false }); this.loadDocument(nextProps); } } @@ -87,6 +90,8 @@ type Props = { if (document) { this.props.ui.setActiveDocument(document); document.view(); + } else { + this.setState({ notFound: true }); } } }; @@ -153,6 +158,11 @@ type Props = { this.setState({ isDragging: false }); }; + renderNotFound() { + const { match } = this.props; + return ; + } + render() { const isNew = this.props.newDocument; const isEditing = !!this.props.match.params.edit || isNew; @@ -160,6 +170,10 @@ type Props = { const titleText = get(this.document, 'title', ''); const document = this.document; + if (this.state.notFound) { + return this.renderNotFound(); + } + return ( {this.state.isDragging && From 23a2c7a052b7a8f631f75a582a9885d0e8a29396 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 10 Sep 2017 13:05:54 -0400 Subject: [PATCH 2/3] added a comment + more reliable edit cancel --- frontend/scenes/Document/Document.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index b125a9e8c..a824f4367 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -91,6 +91,7 @@ type Props = { this.props.ui.setActiveDocument(document); document.view(); } else { + // Render 404 with search this.setState({ notFound: true }); } } @@ -147,7 +148,8 @@ type Props = { }; onCancel = () => { - this.props.history.goBack(); + if (!this.document) return; + this.props.history.push(this.document.url); }; onStartDragging = () => { From 2b9ab3aa8594c115ebb9a82691b0605f7279b981 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 10 Sep 2017 13:08:50 -0400 Subject: [PATCH 3/3] no reason for this --- frontend/scenes/Document/Document.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index a824f4367..dbdb66f39 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -161,8 +161,7 @@ type Props = { }; renderNotFound() { - const { match } = this.props; - return ; + return ; } render() {