From 2ac34a9799158e348ab5aa22a336ef8f18e27c42 Mon Sep 17 00:00:00 2001 From: max-voronov <70445727+max-voronov@users.noreply.github.com> Date: Thu, 22 Oct 2020 01:26:46 +0300 Subject: [PATCH] chore(client): refactor NotFoundPage (#39777) --- .../ShowProfileOrFourOhFour.js | 4 +- client/src/components/FourOhFour/index.js | 83 +++++++------------ client/src/pages/404.js | 4 +- 3 files changed, 34 insertions(+), 57 deletions(-) diff --git a/client/src/client-only-routes/ShowProfileOrFourOhFour.js b/client/src/client-only-routes/ShowProfileOrFourOhFour.js index 4b8dffc7fe..c752db7d3b 100644 --- a/client/src/client-only-routes/ShowProfileOrFourOhFour.js +++ b/client/src/client-only-routes/ShowProfileOrFourOhFour.js @@ -10,7 +10,7 @@ import { fetchProfileForUser, usernameSelector } from '../redux'; -import FourOhFourPage from '../components/FourOhFour'; +import FourOhFour from '../components/FourOhFour'; import Profile from '../components/profile/Profile'; import { isBrowser } from '../../utils/index'; @@ -69,7 +69,7 @@ class ShowProfileOrFourOhFour extends Component { // We have a response from the API, but there is nothing in the store // for /:maybeUser. We can derive from this state the /:maybeUser is not // a user the API recognises, so we 404 - return ; + return ; } // We have a response from the API, and we have some state in the diff --git a/client/src/components/FourOhFour/index.js b/client/src/components/FourOhFour/index.js index c6821879ce..39d70d5d7c 100644 --- a/client/src/components/FourOhFour/index.js +++ b/client/src/components/FourOhFour/index.js @@ -1,6 +1,6 @@ -import React, { Component } from 'react'; +import React from 'react'; import Helmet from 'react-helmet'; -import { Loader, Spacer } from '../../components/helpers'; +import { Spacer } from '../../components/helpers'; import { Link } from 'gatsby'; import notFoundLogo from '../../assets/images/freeCodeCamp-404.svg'; @@ -8,57 +8,34 @@ import { randomQuote } from '../../utils/get-words'; import './404.css'; -class NotFoundPage extends Component { - constructor(props) { - super(props); - this.state = { - randomQuote: null - }; - } - - componentDidMount() { - this.updateQuote(); - } - - updateQuote() { - this.setState({ - randomQuote: randomQuote() - }); - } - - render() { - return ( -
- - 404 Not Found +const FourOhFour = () => { + const quote = randomQuote(); + return ( +
+ + 404 Not Found + +

Page not found.

+ +
+

+ We couldn't find what you were looking for, but here is a quote: +

-

Page not found.

- - {this.state.randomQuote ? ( -
-

- We couldn't find what you were looking for, but here is a - quote: -

- -
-

- - {this.state.randomQuote.quote} -

-

- {this.state.randomQuote.author}

-
-
- ) : ( - - )} - - - View the Curriculum - +
+

+ + {quote.quote} +

+

- {quote.author}

+
- ); - } -} + + + View the Curriculum + +
+ ); +}; -export default NotFoundPage; +export default FourOhFour; diff --git a/client/src/pages/404.js b/client/src/pages/404.js index e6c64971f1..e0e2052f31 100644 --- a/client/src/pages/404.js +++ b/client/src/pages/404.js @@ -1,7 +1,7 @@ import React from 'react'; import { Router } from '@reach/router'; -import NotFoundPage from '../components/FourOhFour'; +import FourOhFour from '../components/FourOhFour'; /* eslint-disable max-len */ import ShowProfileOrFourOhFour from '../client-only-routes/ShowProfileOrFourOhFour'; /* eslint-enable max-len */ @@ -10,7 +10,7 @@ function FourOhFourPage() { return ( - + ); }