From 40452b71bf68a31ab7fdeacbe76053da99bb78aa Mon Sep 17 00:00:00 2001 From: David Ralph Date: Tue, 22 Oct 2019 15:44:49 +0100 Subject: [PATCH] eat all the cheese, push all the things --- src/components/Background.jsx | 5 +---- src/components/Clock.jsx | 4 +--- src/components/Credit.jsx | 9 +++++---- src/components/Greeting.jsx | 4 +++- src/components/Quote.jsx | 5 +---- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/components/Background.jsx b/src/components/Background.jsx index 5987f489..eaf03fb6 100644 --- a/src/components/Background.jsx +++ b/src/components/Background.jsx @@ -2,9 +2,6 @@ import React from 'react'; import Fetch from 'unfetch'; -// Pick random number -const randomInt = (min, max) => { return Math.floor(Math.random() * (max - min + 1)) + min; }; - export default class Background extends React.Component { async getAndSetBackground() { try { // First we try and get an image from the API... @@ -17,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/${randomInt(1, 25)}.jpeg)`; + document.getElementById('root').style.backgroundImage = `url(../offline-images/${Math.floor(Math.random() * (20 - 1 + 1)) + 1})`; } } diff --git a/src/components/Clock.jsx b/src/components/Clock.jsx index 41046ed1..1869d296 100644 --- a/src/components/Clock.jsx +++ b/src/components/Clock.jsx @@ -13,13 +13,11 @@ export default class Clock extends React.Component { startTime() { const today = new Date(); // Get the current date let h = today.getHours(); // Get hours - const ampm = h >= 12 ? 'PM' : 'AM'; // Set AM/PM - const m = today.getMinutes(); // Get minutes // const s = today.getSeconds(); if (h > 12) h = h - 12; - this.setState({ date: `${('0' + h).slice(-2)}:${('0' + m).slice(-2)}`, ampm: ampm }); + this.setState({ date: `${('0' + h).slice(-2)}:${('0' + today.getMinutes()).slice(-2)}`, ampm: h >= 12 ? 'PM' : 'AM' }); this.timeout = setTimeout(() => this.startTime(), 500); } diff --git a/src/components/Credit.jsx b/src/components/Credit.jsx index 6d538814..8b57c4fa 100644 --- a/src/components/Credit.jsx +++ b/src/components/Credit.jsx @@ -7,10 +7,11 @@ export default class Search extends React.Component { render() { return (
- {/*

*/} -

-
- + {/*

*/} +

+
+ +

); diff --git a/src/components/Greeting.jsx b/src/components/Greeting.jsx index 65f35a73..8fe08bee 100644 --- a/src/components/Greeting.jsx +++ b/src/components/Greeting.jsx @@ -22,6 +22,8 @@ export default class Greeting extends React.Component { } render() { - return

{this.state.greeting}

; + return

+ {this.state.greeting} +

; } } \ No newline at end of file diff --git a/src/components/Quote.jsx b/src/components/Quote.jsx index 75fd9311..a69e3b30 100644 --- a/src/components/Quote.jsx +++ b/src/components/Quote.jsx @@ -3,9 +3,6 @@ import React from 'react'; import Fetch from 'unfetch'; import quotes from '../quotes.json'; -// Pick randon number -const randomInt = (min, max) => { return Math.floor(Math.random() * (max - min + 1)) + min; }; - export default class Quote extends React.Component { constructor(...args) { super(...args); @@ -21,7 +18,7 @@ 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 = randomInt(1, 20); + const num = Math.floor(Math.random() * (20 - 1 + 1)) + 1; // Get random number between 1-20 this.setState({ quote: quotes[num].quote, author: quotes[num].author }); } }