From 408f8c4502cea8cc6534edf946c77f50725d7f4d Mon Sep 17 00:00:00 2001 From: David Ralph Date: Sat, 5 Dec 2020 13:48:14 +0000 Subject: [PATCH] optimise and fix quote api support for addons --- package.json | 11 ++- .../settings/sections/SearchSettings.jsx | 5 +- src/components/widgets/quote/Quote.jsx | 12 +-- .../widgets/quote/offline_quotes.json | 80 +++++++++++++++++++ src/modules/helpers/marketplace.js | 4 +- 5 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 src/components/widgets/quote/offline_quotes.json diff --git a/package.json b/package.json index c47582d0..8a1a2fb2 100644 --- a/package.json +++ b/package.json @@ -11,15 +11,14 @@ "license": "BSD-3-Clause", "version": "5.0.0", "dependencies": { - "@material-ui/core": "4.11.1", - "@material-ui/icons": "4.9.1", - "@muetab/quotes": "^1.0.0", + "@material-ui/core": "4.11.2", + "@material-ui/icons": "4.11.2", "deepmerge": "^4.2.2", - "fontsource-lexend-deca": "^3.0.10", + "fontsource-lexend-deca": "^3.0.11", "fontsource-roboto": "^3.0.3", "react": "17.0.1", "react-beforeunload": "^2.4.0", - "react-clock": "^2.4.0", + "react-clock": "^3.0.0", "react-color-gradient-picker": "^0.1.2", "react-date-picker": "^8.0.5", "react-dom": "17.0.1", @@ -29,7 +28,7 @@ }, "devDependencies": { "node-sass": "4.14.1", - "react-scripts": "^3.4.4" + "react-scripts": "^4.0.1" }, "scripts": { "start": "react-scripts start", diff --git a/src/components/modals/settings/sections/SearchSettings.jsx b/src/components/modals/settings/sections/SearchSettings.jsx index 8b80f233..74d39f84 100644 --- a/src/components/modals/settings/sections/SearchSettings.jsx +++ b/src/components/modals/settings/sections/SearchSettings.jsx @@ -15,14 +15,15 @@ export default class SearchSettings extends React.PureComponent { } componentDidMount() { - if (localStorage.getItem('searchEngine') === 'custom') { + const searchEngine = localStorage.getItem('searchEngine'); + if (searchEngine === 'custom') { const input = document.getElementById('searchEngineInput'); input.style.display = 'block'; input.enabled = 'true'; document.getElementById('customSearchEngine').value = localStorage.getItem('customSearchEngine'); } else localStorage.removeItem('customSearchEngine'); - document.getElementById('searchEngine').value = localStorage.getItem('searchEngine'); + document.getElementById('searchEngine').value = searchEngine; } render() { diff --git a/src/components/widgets/quote/Quote.jsx b/src/components/widgets/quote/Quote.jsx index 535c57dd..6b0b15b8 100644 --- a/src/components/widgets/quote/Quote.jsx +++ b/src/components/widgets/quote/Quote.jsx @@ -1,5 +1,4 @@ import React from 'react'; -import Quotes from '@muetab/quotes'; import FileCopy from '@material-ui/icons/FilterNone'; import { toast } from 'react-toastify'; import * as Constants from '../../../modules/constants'; @@ -9,6 +8,8 @@ import StarIcon2 from '@material-ui/icons/StarBorder'; import './quote.scss'; +const quotes = require('./offline_quotes.json'); + export default class Quote extends React.PureComponent { constructor(...args) { super(...args); @@ -20,7 +21,7 @@ export default class Quote extends React.PureComponent { } doOffline() { - const quote = Quotes.random(); // Get a random quote from our local package + const quote = quotes[Math.floor(Math.random() * quotes.length)]; // Get a random quote from our local package this.setState({ quote: '"' + quote.quote + '"', author: quote.author @@ -42,14 +43,13 @@ export default class Quote extends React.PureComponent { } async getQuote() { - const quotePackAPI = JSON.parse(localStorage.getItem('quote_api')); + const quotePackAPI = JSON.parse(localStorage.getItem('quoteAPI')); if (quotePackAPI) { try { const data = await (await fetch(quotePackAPI.url)).json(); - const author = quotePackAPI.authorOverride || data[quotePackAPI.author]; return this.setState({ - quote: '"' + data[quotePackAPI.quote] + '"', - author: author + quote: '"' + data.quote + '"', + author: quotePackAPI.author || data.author }); } catch (e) { return this.getQuotePack(); diff --git a/src/components/widgets/quote/offline_quotes.json b/src/components/widgets/quote/offline_quotes.json new file mode 100644 index 00000000..687340dc --- /dev/null +++ b/src/components/widgets/quote/offline_quotes.json @@ -0,0 +1,80 @@ +[ + { + "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." + } +] \ No newline at end of file diff --git a/src/modules/helpers/marketplace.js b/src/modules/helpers/marketplace.js index b20e5360..1c710ebe 100644 --- a/src/modules/helpers/marketplace.js +++ b/src/modules/helpers/marketplace.js @@ -15,7 +15,7 @@ export default class MarketplaceFunctions { break; case 'quote_packs': localStorage.removeItem('quote_packs'); - localStorage.removeItem('quote_api'); + localStorage.removeItem('quoteAPI'); break; default: try { localStorage.removeItem(type); } @@ -46,7 +46,7 @@ export default class MarketplaceFunctions { break; case 'photo_packs': localStorage.setItem('photo_packs', JSON.stringify(input.photos)); break; case 'quote_packs': - if (input.quote_api) localStorage.setItem('quote_api', JSON.stringify(input.quote_api)); + if (input.quote_api) localStorage.setItem('quoteAPI', JSON.stringify(input.quote_api)); localStorage.setItem('quote_packs', JSON.stringify(input.quotes)); break; default: break;