From 783155cabd01a5c594eb3c07d90525a9851452de Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Fri, 13 Sep 2019 13:54:52 +0300 Subject: [PATCH] show a simple 404 page --- frontend/src/Documents/DocumentEdit.tsx | 15 ++++++------- frontend/src/Documents/DocumentView.tsx | 7 ++++++- frontend/src/Home/Home.tsx | 28 +++++++++++++------------ frontend/src/NotFound.tsx | 5 +++++ 4 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 frontend/src/NotFound.tsx diff --git a/frontend/src/Documents/DocumentEdit.tsx b/frontend/src/Documents/DocumentEdit.tsx index 9d7f74a..0f8d532 100644 --- a/frontend/src/Documents/DocumentEdit.tsx +++ b/frontend/src/Documents/DocumentEdit.tsx @@ -8,6 +8,7 @@ import { Dispatch } from "redux"; import { IDocumentJSON } from "~../../src/entity/Document"; import { showDeletionToast } from "~AppToaster"; import { LoadingStub } from "~LoadingStub"; +import { NotFound } from "~NotFound"; import { deleteDocCancel, deleteDocStart, @@ -59,7 +60,9 @@ export class DocumentEditComponent extends React.PureComponent< public render() { if (this.state.loaded) { const doc = this.props.allDocs[this.state.id]; - + if (!doc) { + return ; + } return (
@@ -165,17 +168,11 @@ export class DocumentEditComponent extends React.PureComponent< this.props.fetchDocs(); } else { const { id } = this.props.match.params as any; - if ( - !this.state.loaded && - this.props.allDocs && - this.props.allDocs[id] - ) { - const doc = this.props.allDocs[id]; - + if (!this.state.loaded && this.props.allDocs) { this.setState({ ...this.state, loaded: true, - id: doc.id, + id, }); } } diff --git a/frontend/src/Documents/DocumentView.tsx b/frontend/src/Documents/DocumentView.tsx index 285183c..393f20a 100644 --- a/frontend/src/Documents/DocumentView.tsx +++ b/frontend/src/Documents/DocumentView.tsx @@ -8,6 +8,7 @@ import { RouteComponentProps, withRouter } from "react-router"; import { Dispatch } from "redux"; import { IDocumentJSON } from "~../../src/entity/Document"; import { LoadingStub } from "~LoadingStub"; +import { NotFound } from "~NotFound"; import { fetchDocsStart } from "~redux/docs/actions"; import { IAppState } from "~redux/reducers"; import { CodeBlock } from "./CodeBlock"; @@ -27,8 +28,12 @@ export class DocumentViewComponent extends React.PureComponent< > { public render() { const { id } = this.props.match.params as any; - if (this.props.allDocs && this.props.allDocs[id]) { + if (this.props.allDocs) { const doc = this.props.allDocs[id]; + if (!doc) { + return ; + } + return (
diff --git a/frontend/src/Home/Home.tsx b/frontend/src/Home/Home.tsx index b8cee68..a59214e 100644 --- a/frontend/src/Home/Home.tsx +++ b/frontend/src/Home/Home.tsx @@ -58,11 +58,13 @@ export class HomeComponent extends React.PureComponent { if ((this.props.match.params as any).id && this.props.allDocs) { const { id } = this.props.match.params as any; - breadcrumbs.push({ - icon: "document", - text: this.props.allDocs[id].name, - onClick: () => this.props.history.push(`/docs/${id}`), - }); + if (this.props.allDocs[id]) { + breadcrumbs.push({ + icon: "document", + text: this.props.allDocs[id].name, + onClick: () => this.props.history.push(`/docs/${id}`), + }); + } } return ( @@ -82,8 +84,8 @@ export class HomeComponent extends React.PureComponent { {this.props.uploading || this.props.dirty ? ( ) : ( - - )} + + )} { onClick={this.props.dispatchToggleDarkMode} /> ) : ( - - )} + + )} ); } diff --git a/frontend/src/NotFound.tsx b/frontend/src/NotFound.tsx new file mode 100644 index 0000000..fbe2649 --- /dev/null +++ b/frontend/src/NotFound.tsx @@ -0,0 +1,5 @@ +import * as React from "react"; + +export function NotFound() { + return
404
; +}