This commit is contained in:
David Ralph
2019-11-29 12:12:34 +00:00
parent cde3743ff8
commit 2fa7567cf3
4 changed files with 18 additions and 14 deletions

View File

@@ -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
}
}

View File

@@ -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);
}

View File

@@ -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
}
}