From 2fa7567cf3e7973162ddce31979c21f7e14d67bd Mon Sep 17 00:00:00 2001 From: David Ralph Date: Fri, 29 Nov 2019 12:12:34 +0000 Subject: [PATCH] improve --- src/App.jsx | 2 +- src/components/Background.jsx | 2 +- src/components/Clock.jsx | 16 +++++++++------- src/components/Quote.jsx | 12 +++++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 4f078d01..824291f3 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -7,7 +7,7 @@ import Quote from './components/Quote'; import Search from './components/Search'; import Credit from './components/Credit'; import Navbar from './components/Navbar'; -import './css/index.css'; +import './css/index.css'; // Import the compiled Sass //* App export default class App extends React.Component { diff --git a/src/components/Background.jsx b/src/components/Background.jsx index 71fd51da..69feb15f 100644 --- a/src/components/Background.jsx +++ b/src/components/Background.jsx @@ -14,7 +14,7 @@ export default class Background extends React.Component { } catch (e) { // ..and if that fails we load one locally document.getElementById('backgroundCredits').style.display = 'none'; document.getElementById('photographer').innerText = 'Photo from Pexels'; - document.getElementById('root').style.backgroundImage = `url(../offline-images/${Math.floor(Math.random() * (20 - 1 + 1)) + 1})`; + document.getElementById('root').style.backgroundImage = `url(../offline-images/${Math.floor(Math.random() * (20 - 1 + 1)) + 1})`; // There are 20 images in the offline-images folder } } diff --git a/src/components/Clock.jsx b/src/components/Clock.jsx index 0854701d..0ecf986f 100644 --- a/src/components/Clock.jsx +++ b/src/components/Clock.jsx @@ -5,28 +5,30 @@ export default class Clock extends React.Component { constructor(...args) { super(...args); this.state = { - date: ``, - ampm: ``, + date: '', + ampm: '', }; } startTime() { - const today = new Date(); // Get the current date + const t = new Date(); // Get the current date let h = today.getHours(); // Get hours // const s = today.getSeconds(); - if (h > 12) h = h - 12; + if (h > 12) h = h - 12; // Forgot what this does, might remove later if it doesn't do anything - this.setState({ date: `${('0' + h).slice(-2)}:${('0' + today.getMinutes()).slice(-2)}`, ampm: h >= 12 ? 'AM' : 'PM' }); + this.setState({ + date: `${('0' + h).slice(-2)}:${('0' + t.getMinutes()).slice(-2)}`, ampm: h >= 12 ? 'AM' : 'PM' + }); // Set time - this.timeout = setTimeout(() => this.startTime(), 500); + this.timeout = setTimeout(() => this.startTime(), 500); // Update the clock every 500 milliseconds } componentDidMount() { this.startTime(); } - componentWillUnmount() { + componentWillUnmount() { // Do we need this? clearTimeout(this.timeout); } diff --git a/src/components/Quote.jsx b/src/components/Quote.jsx index 21b1e102..4636c24d 100644 --- a/src/components/Quote.jsx +++ b/src/components/Quote.jsx @@ -7,8 +7,8 @@ export default class Quote extends React.Component { constructor(...args) { super(...args); this.state = { - quote: ``, - author: `` + quote: '', + author: '' }; } @@ -18,9 +18,11 @@ export default class Quote extends React.Component { data = await data.json(); this.setState({ quote: data.quote, author: data.author }); } catch (e) { // ..and if that fails we load one locally - // const num = Math.floor(Math.random() * (20 - 1 + 1)) + 1; // Get random number between 1-20 - const quote = quotes[Math.floor(Math.random() * quotes.length)]; - this.setState({ quote: quote.quote, author: quote.author }); + const quote = quotes[Math.floor(Math.random() * quotes.length)]; // Get a random quote from quotes.json + this.setState({ + quote: quote.quote, + author: quote.author + }); // Set the quote } }