forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix random page flickering on page load freeCodeCamp#256 (freeCodeCam…
…p#264) * fix random page flickering on page load freeCodeCamp#256 * loaded quote in componentDidMount to prevent flickering * added spinner when quote has not yet loaded * use better standards
- Loading branch information
1 parent
848ede2
commit ce8b086
Showing
1 changed file
with
48 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,61 @@ | ||
import React from 'react'; | ||
import Helmet from 'react-helmet'; | ||
import Spinner from 'react-spinkit'; | ||
import { Link } from 'gatsby'; | ||
|
||
import './404.css'; | ||
import notFoundLogo from '../../static/img/freeCodeCamp-404.svg'; | ||
import { quotes } from '../../static/json/quotes.json'; | ||
|
||
let randomQuote = quotes[Math.floor(Math.random() * quotes.length)]; | ||
class NotFoundPage extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
randomQuote: null | ||
} | ||
} | ||
|
||
const NotFoundPage = () => ( | ||
<div className='notfound-page-wrapper'> | ||
<Helmet title='Page Not Found | freeCodeCamp' /> | ||
componentDidMount() { | ||
this.updateQuote(); | ||
} | ||
|
||
<img alt='learn to code at freeCodeCamp 404' src={notFoundLogo} /> | ||
<h1>NOT FOUND</h1> | ||
<p>We couldn't find what you were looking for, but here is a quote:</p> | ||
updateQuote() { | ||
this.setState({ | ||
randomQuote: quotes[Math.floor(Math.random() * quotes.length)] | ||
}); | ||
} | ||
|
||
<div className='quote-wrapper'> | ||
<p className='quote'> | ||
<span>“</span> | ||
{randomQuote.quote} | ||
</p> | ||
<p className='author'>- {randomQuote.author}</p> | ||
</div> | ||
|
||
<Link className='btn-curriculum' to='/'> | ||
View the Curriculum | ||
</Link> | ||
</div> | ||
); | ||
render() { | ||
return ( | ||
<div className='notfound-page-wrapper'> | ||
<Helmet title='Page Not Found | freeCodeCamp' /> | ||
<img alt='learn to code at freeCodeCamp 404' src={notFoundLogo} /> | ||
<h1>NOT FOUND</h1> | ||
{ | ||
this.state.randomQuote ? ( | ||
<div> | ||
<p> | ||
We couldn't find what you were looking for, but here is a | ||
quote: | ||
</p> | ||
<div className='quote-wrapper'> | ||
<p className='quote'> | ||
<span>“</span> | ||
{this.state.randomQuote.quote} | ||
</p> | ||
<p className='author'>- {this.state.randomQuote.author}</p> | ||
</div> | ||
</div> | ||
) : ( | ||
<Spinner color='#006400' name='ball-clip-rotate-multiple' /> | ||
) | ||
} | ||
<Link className='btn-curriculum' to='/'> | ||
View the Curriculum | ||
</Link> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default NotFoundPage; |