show a simple 404 page

This commit is contained in:
2019-09-13 13:54:52 +03:00
parent 0b68dc2963
commit 783155cabd
4 changed files with 32 additions and 23 deletions

View File

@@ -8,6 +8,7 @@ import { Dispatch } from "redux";
import { IDocumentJSON } from "~../../src/entity/Document"; import { IDocumentJSON } from "~../../src/entity/Document";
import { showDeletionToast } from "~AppToaster"; import { showDeletionToast } from "~AppToaster";
import { LoadingStub } from "~LoadingStub"; import { LoadingStub } from "~LoadingStub";
import { NotFound } from "~NotFound";
import { import {
deleteDocCancel, deleteDocCancel,
deleteDocStart, deleteDocStart,
@@ -59,7 +60,9 @@ export class DocumentEditComponent extends React.PureComponent<
public render() { public render() {
if (this.state.loaded) { if (this.state.loaded) {
const doc = this.props.allDocs[this.state.id]; const doc = this.props.allDocs[this.state.id];
if (!doc) {
return <NotFound />;
}
return ( return (
<div className="document"> <div className="document">
<div className="documentHeader"> <div className="documentHeader">
@@ -165,17 +168,11 @@ export class DocumentEditComponent extends React.PureComponent<
this.props.fetchDocs(); this.props.fetchDocs();
} else { } else {
const { id } = this.props.match.params as any; const { id } = this.props.match.params as any;
if ( if (!this.state.loaded && this.props.allDocs) {
!this.state.loaded &&
this.props.allDocs &&
this.props.allDocs[id]
) {
const doc = this.props.allDocs[id];
this.setState({ this.setState({
...this.state, ...this.state,
loaded: true, loaded: true,
id: doc.id, id,
}); });
} }
} }

View File

@@ -8,6 +8,7 @@ import { RouteComponentProps, withRouter } from "react-router";
import { Dispatch } from "redux"; import { Dispatch } from "redux";
import { IDocumentJSON } from "~../../src/entity/Document"; import { IDocumentJSON } from "~../../src/entity/Document";
import { LoadingStub } from "~LoadingStub"; import { LoadingStub } from "~LoadingStub";
import { NotFound } from "~NotFound";
import { fetchDocsStart } from "~redux/docs/actions"; import { fetchDocsStart } from "~redux/docs/actions";
import { IAppState } from "~redux/reducers"; import { IAppState } from "~redux/reducers";
import { CodeBlock } from "./CodeBlock"; import { CodeBlock } from "./CodeBlock";
@@ -27,8 +28,12 @@ export class DocumentViewComponent extends React.PureComponent<
> { > {
public render() { public render() {
const { id } = this.props.match.params as any; 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]; const doc = this.props.allDocs[id];
if (!doc) {
return <NotFound />;
}
return ( return (
<div className="document"> <div className="document">
<div className="documentHeader"> <div className="documentHeader">

View File

@@ -58,11 +58,13 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
if ((this.props.match.params as any).id && this.props.allDocs) { if ((this.props.match.params as any).id && this.props.allDocs) {
const { id } = this.props.match.params as any; const { id } = this.props.match.params as any;
breadcrumbs.push({ if (this.props.allDocs[id]) {
icon: "document", breadcrumbs.push({
text: this.props.allDocs[id].name, icon: "document",
onClick: () => this.props.history.push(`/docs/${id}`), text: this.props.allDocs[id].name,
}); onClick: () => this.props.history.push(`/docs/${id}`),
});
}
} }
return ( return (
@@ -82,8 +84,8 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
{this.props.uploading || this.props.dirty ? ( {this.props.uploading || this.props.dirty ? (
<Spinner size={20} /> <Spinner size={20} />
) : ( ) : (
<Icon icon="saved" /> <Icon icon="saved" />
)} )}
</Button> </Button>
<Popover <Popover
target={ target={
@@ -158,12 +160,12 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
onClick={this.props.dispatchToggleDarkMode} onClick={this.props.dispatchToggleDarkMode}
/> />
) : ( ) : (
<Menu.Item <Menu.Item
icon="moon" icon="moon"
text="Dark Mode" text="Dark Mode"
onClick={this.props.dispatchToggleDarkMode} onClick={this.props.dispatchToggleDarkMode}
/> />
)} )}
</Menu> </Menu>
); );
} }

View File

@@ -0,0 +1,5 @@
import * as React from "react";
export function NotFound() {
return <div>404</div>;
}