diff --git a/package.json b/package.json index 878be99a..b64f1bae 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@material-ui/core": "^4.7.0", "@material-ui/icons": "^4.5.1", + "@muetab/quotes": "^1.0.0", "react": "^16.12.0", "react-dom": "^16.12.0", "react-scripts": "3.2.0" diff --git a/src/components/Background.jsx b/src/components/Background.jsx index 4ab1456c..f73b00f5 100644 --- a/src/components/Background.jsx +++ b/src/components/Background.jsx @@ -11,9 +11,94 @@ export default class Background extends React.Component { document.getElementById('photographer').innerText = `Photo by ${data.photographer}`; document.getElementById('location').innerText = `${data.location}`; } catch (e) { // ..and if that fails we load one locally + let photographer; + const photo = Math.floor(Math.random() * (20 - 1 + 1)) + 1; // There are 20 images in the offline-images folder 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})`; // There are 20 images in the offline-images folder + // eslint-disable-next-line default-case + switch (photo) { // Select photographer based on image file number + case 1: { + photographer = 'Tirachard Kumtanom (Pexels)'; + break; + } + case 2: { + photographer = 'Pixabay (Pexels)'; + break; + } + case 3: { + photographer = 'Pixabay (Pexels)'; + break; + } + case 4: { + photographer = 'Sohail Na (Pexels)'; + break; + } + case 5: { + photographer = 'Unknown (Pexels)'; + break; + } + case 6: { + photographer = 'Unknown (Pexels)'; + break; + } + case 7: { + photographer = 'Miriam Espacio (Pexels)'; + break; + } + case 8: { + photographer = 'Unknown (Pexels)'; + break; + } + case 9: { + photographer = 'Pixabay (Pexels)'; + break; + } + case 10: { + photographer = 'NO NAME (Pexels)'; + break; + } + case 11: { + photographer = 'Pixabay (Pexels)'; + break; + } + case 12: { + photographer = 'Unknown (Pexels)'; + break; + } + case 13: { + photographer = 'Pixabay (Pexels)'; + break; + } + case 14: { + photographer = 'Pixabay (Pexels)'; + break; + } + case 15: { + photographer = 'Pixabay (Pexels)'; + break; + } + case 16: { + photographer = 'Unknown (Pexels)'; + break; + } + case 17: { + photographer = 'Unknown (Pexels)'; + break; + } + case 18: { + photographer = 'Unknown (Pexels)'; + break; + } + case 19: { + photographer = 'Unknown (Pexels)'; + break; + } + case 20: { + photographer = 'Fabian Wiktor (Pexels)'; + break; + } + } + document.getElementById('photographer').innerText = `Photo by ${photographer}`; + document.getElementById('root').style.backgroundImage = `url(../offline-images/${photo}.jpeg)`; } } diff --git a/src/components/Credit.jsx b/src/components/Credit.jsx index 8b57c4fa..a44781b1 100644 --- a/src/components/Credit.jsx +++ b/src/components/Credit.jsx @@ -3,7 +3,7 @@ import RoomIcon from '@material-ui/icons/Room'; import React from 'react'; -export default class Search extends React.Component { +export default class Credit extends React.Component { render() { return (
diff --git a/src/components/Greeting.jsx b/src/components/Greeting.jsx index 9753b78a..6cfce1dc 100644 --- a/src/components/Greeting.jsx +++ b/src/components/Greeting.jsx @@ -23,9 +23,10 @@ export default class Greeting extends React.Component { if (t.getMonth() === 0 && t.getDate() === 1) g = 'Happy new year'; // If the date is January 1st, set it to new year else if (t.getMonth() === 11 && t.getDate() === 25) g = 'Merry Christmas'; // If it's December 25th, set it to xmas else if (t.getMonth() === 9 && t.getDate() === 31) g = 'Happy Halloween'; // If it's October 31st, set it to halloween + this.setState({ greeting: g - }); // Set the state to the time string + }); // Set the state to the greeting string } componentDidMount() { diff --git a/src/components/Quote.jsx b/src/components/Quote.jsx index 81ded67d..68412ba8 100644 --- a/src/components/Quote.jsx +++ b/src/components/Quote.jsx @@ -1,6 +1,6 @@ //* Imports import React from 'react'; -import quotes from '../quotes.json'; +import Quotes from '@muetab/quotes'; export default class Quote extends React.Component { constructor(...args) { @@ -15,9 +15,12 @@ export default class Quote extends React.Component { try { // First we try and get a quote from the API... let data = await fetch('https://api.muetab.xyz/getQuote'); data = await data.json(); - this.setState({ quote: data.quote, author: data.author }); + this.setState({ + quote: data.quote, + author: data.author + }); } catch (e) { // ..and if that fails we load one locally - const quote = quotes[Math.floor(Math.random() * quotes.length)]; // Get a random quote from quotes.json + const quote = Quotes.random(); // Get a random quote from our local package this.setState({ quote: quote.quote, author: quote.author diff --git a/src/quotes.json b/src/quotes.json deleted file mode 100644 index 4caf0b95..00000000 --- a/src/quotes.json +++ /dev/null @@ -1,80 +0,0 @@ -[ - { - "author": "Robert De Niro", - "quote": "Time goes on. So whatever you’re going to do, do it. Do it now. Don’t wait." - }, - { - "author": "Walt Disney", - "quote": "All our dreams can come true, if we have the courage to pursue them." - }, - { - "author": "Confucius", - "quote": "It does not matter how slowly you go as long as you do not stop." - }, { - "author": "Roy T. Bennett", - "quote": "Believe in yourself. You are braver than you think, more talented than you know, and capable of more than you imagine." - }, { - "author": "Wayne Dyer", - "quote": "If you believe it will work out, you’ll see opportunities. If you believe it won’t, you will see obstacles." - }, { - "author": "George Addair", - "quote": "Everything you’ve ever wanted is on the other side of fear." - }, { - "author": "Winston Churchill", - "quote": "Success is not final, failure is not fatal: it is the courage to continue that counts." - }, { - "author": "Paulo Coelho", - "quote": "There is only one thing that makes a dream impossible to achieve: the fear of failure" - }, { - "author": "Brian Tracy", - "quote": "Your true success in life begins only when you make the commitment to become excellent at what you do." - }, { - "author": "Chantal Sutherland", - "quote": "Believe in yourself, take on your challenges, dig deep within yourself to conquer fears. Never let anyone bring you down. You got to keep going." - }, { - "author": "Les Brown", - "quote": "Too many of us are not living our dreams because we are living our fears." - }, { - "author": "Bob Riley", - "quote": "Hard times don’t create heroes. It is during the hard times when the ‘hero’ within us is revealed." - }, { - "author": "Jack Canfield", - "quote": "If you can tune into your purpose and really align with it, setting goals so that your vision is an expression of that purpose, then life flows much more easily." - }, { - "author": "Napolean Hill", - "quote": "Whatever the mind can conceive and believe, it can achieve." - }, { - "author": "Jim Rohn", - "quote": "Don’t wish it were easier. Wish you were better." - }, { - "author": "Serena Williams", - "quote": "A champion is defined not by their wins but by how they can recover when they fall." - }, { - "author": "Sheryl Sandberg", - "quote": "Motivation comes from working on things we care about." - }, { - "author": "Reese Witherspoon", - "quote": "With the right kind of coaching and determination you can accomplish anything." - }, { - "author": "Hazrat Inayat Khan", - "quote": "Some people look for a beautiful place. Others make a place beautiful." - }, { - "author": "Albert Einstein", - "quote": "Life is like riding a bicycle. To keep your balance, you must keep moving." - }, { - "author": "Walt Disney", - "quote": "The way to get started is to quit talking and begin doing." - }, { - "author": "Winston Churchill", - "quote": "A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty." - }, { - "author": "Will Rogers", - "quote": "Don't let yesterday take up too much of today." - }, { - "author": "Vince Lombardi", - "quote": "It's not whether you get knocked down, it's whether you get up." - }, { - "author": "Steve Jobs", - "quote": "If you are working on something that you really care about, you don’t have to be pushed. The vision pulls you." - } -]