diff --git a/src/components/modals/main/settings/sections/Quote.jsx b/src/components/modals/main/settings/sections/Quote.jsx
index 6ecdb2ac..2b3b48f4 100644
--- a/src/components/modals/main/settings/sections/Quote.jsx
+++ b/src/components/modals/main/settings/sections/Quote.jsx
@@ -4,23 +4,56 @@ import Checkbox from '../Checkbox';
import Text from '../Text';
import Switch from '../Switch';
import Slider from '../Slider';
+import Dropdown from '../Dropdown';
-export default function QuoteSettings() {
- const { quote } = window.language.modals.main.settings.sections;
+export default class QuoteSettings extends React.PureComponent {
+ constructor() {
+ super();
+ this.state = {
+ quoteType: localStorage.getItem('quoteType') || 'api',
+ };
+ }
- return (
- <>
-
{quote.title}
-
-
-
-
-
+ marketplaceType = () => {
+ if (localStorage.getItem('quote_packs')) {
+ return ;
+ }
+ }
- {quote.buttons.title}
-
-
-
- >
- );
+ render() {
+ const { quote } = window.language.modals.main.settings.sections;
+
+ let quoteSettings;
+
+ const customSettings = (
+ <>
+
+
+ >
+ );
+
+ switch (this.state.quoteType) {
+ case 'custom': quoteSettings = customSettings; break;
+ }
+
+ return (
+ <>
+ {quote.title}
+
+
+ this.setState({ quoteType: value })} category='quote'>
+ {this.marketplaceType()}
+
+
+
+ {quoteSettings}
+
+
+ {quote.buttons.title}
+
+
+
+ >
+ );
+ }
}
\ No newline at end of file
diff --git a/src/components/modals/main/tabs/backend/Tab.jsx b/src/components/modals/main/tabs/backend/Tab.jsx
index 58febf06..1ea71343 100644
--- a/src/components/modals/main/tabs/backend/Tab.jsx
+++ b/src/components/modals/main/tabs/backend/Tab.jsx
@@ -39,7 +39,7 @@ function Tab(props) {
}
const settings = window.language.modals.main.settings.sections;
- const { navbar, marketplace, addons }= window.language.modals.main;
+ const { navbar, marketplace, addons } = window.language.modals.main;
let icon, divider;
switch (props.label) {
diff --git a/src/components/widgets/quote/Quote.jsx b/src/components/widgets/quote/Quote.jsx
index 25a08951..e265e4ef 100644
--- a/src/components/widgets/quote/Quote.jsx
+++ b/src/components/widgets/quote/Quote.jsx
@@ -42,6 +42,8 @@ export default class Quote extends React.PureComponent {
}
async getQuote() {
+ const offline = (localStorage.getItem('offlineMode') === 'true');
+
const favouriteQuote = localStorage.getItem('favouriteQuote');
if (favouriteQuote) {
return this.setState({
@@ -50,71 +52,87 @@ export default class Quote extends React.PureComponent {
});
}
- const customQuote = localStorage.getItem('customQuote');
- if (customQuote) {
- return this.setState({
- quote: '"' + customQuote + '"',
- author: localStorage.getItem('customQuoteAuthor')
- });
- }
+ switch (localStorage.getItem('quoteType')) {
+ case 'custom':
+ const customQuote = localStorage.getItem('customQuote');
+ if (customQuote) {
+ return this.setState({
+ quote: '"' + customQuote + '"',
+ author: localStorage.getItem('customQuoteAuthor'),
+ type: 'custom'
+ });
+ }
+ break;
+ case 'quote_pack':
+ if (offline) {
+ return this.doOffline();
+ }
- if (localStorage.getItem('offlineMode') === 'true') {
- return this.doOffline();
- }
+ const quotePackAPI = JSON.parse(localStorage.getItem('quoteAPI'));
+ if (quotePackAPI) {
+ try {
+ const data = await (await fetch(quotePackAPI.url)).json();
+ return this.setState({
+ quote: '"' + data.quote + '"',
+ author: quotePackAPI.author || data.author,
+ type: 'quote_pack'
+ });
+ } catch (e) {
+ return this.doOffline();
+ }
+ }
+
+ let quotePack = localStorage.getItem('quote_packs');
+
+ if (quotePack !== null) {
+ quotePack = JSON.parse(quotePack);
+
+ if (quotePack) {
+ const data = quotePack[Math.floor(Math.random() * quotePack.length)];
+ return this.setState({
+ quote: '"' + data.quote + '"',
+ author: data.author,
+ type: 'quote_pack'
+ });
+ } else {
+ return this.doOffline();
+ }
+ }
+ break;
+ case 'api':
+ if (offline) {
+ return this.doOffline();
+ }
- const quotePackAPI = JSON.parse(localStorage.getItem('quoteAPI'));
- if (quotePackAPI) {
- try {
- const data = await (await fetch(quotePackAPI.url)).json();
- return this.setState({
- quote: '"' + data.quote + '"',
- author: quotePackAPI.author || data.author
- });
- } catch (e) {
- return this.doOffline();
- }
- }
+ // First we try and get a quote from the API...
+ try {
+ const quotelanguage = localStorage.getItem('quotelanguage');
+ const data = await (await fetch(window.constants.API_URL + '/quotes/random?language=' + quotelanguage)).json();
- let quotePack = localStorage.getItem('quote_packs');
+ // If we hit the ratelimit, we fallback to local quotes
+ if (data.statusCode === 429) {
+ return this.doOffline();
+ }
- if (quotePack !== null) {
- quotePack = JSON.parse(quotePack);
+ let authorlink = `https://${window.languagecode.split('_')[0]}.wikipedia.org/wiki/${data.author.split(' ').join('_')}`;
+ if (localStorage.getItem('authorLink') === 'false' || data.author === 'Unknown') {
+ authorlink = null;
+ }
- if (quotePack) {
- const data = quotePack[Math.floor(Math.random() * quotePack.length)];
- return this.setState({
- quote: '"' + data.quote + '"',
- author: data.author
- });
- } else {
- return this.doOffline();
- }
- }
-
- // First we try and get a quote from the API...
- try {
- const quotelanguage = localStorage.getItem('quotelanguage');
- const data = await (await fetch(window.constants.API_URL + '/quotes/random?language=' + quotelanguage)).json();
-
- // If we hit the ratelimit, we fallback to local quotes
- if (data.statusCode === 429) {
- return this.doOffline();
- }
-
- let authorlink = `https://${window.languagecode.split('_')[0]}.wikipedia.org/wiki/${data.author.split(' ').join('_')}`;
- if (localStorage.getItem('authorLink') === 'false' || data.author === 'Unknown') {
- authorlink = null;
- }
-
- this.setState({
- quote: '"' + data.quote + '"',
- author: data.author,
- authorlink: authorlink,
- quoteLanguage: quotelanguage
- });
- } catch (e) {
- // ..and if that fails we load one locally
- this.doOffline();
+ this.setState({
+ quote: '"' + data.quote + '"',
+ author: data.author,
+ authorlink: authorlink,
+ quoteLanguage: quotelanguage,
+ type: 'api'
+ });
+ } catch (e) {
+ // ..and if that fails we load one locally
+ this.doOffline();
+ }
+ break;
+ default:
+ break;
}
}
@@ -153,7 +171,7 @@ export default class Quote extends React.PureComponent {
tweet: (localStorage.getItem('tweetButton') === 'false') ? null : this.buttons.tweet
});
- if (!this.state.quote || localStorage.getItem('quotelanguage') !== this.state.quoteLanguage) {
+ if (this.state.type !== localStorage.getItem('quoteType')|| localStorage.getItem('quotelanguage') !== this.state.quoteLanguage) {
this.getQuote();
}
}
@@ -172,6 +190,11 @@ export default class Quote extends React.PureComponent {
document.querySelector('.quoteauthor').style.fontSize = `${0.9 * Number((localStorage.getItem('zoomQuote') || 100) / 100)}em`;
this.init();
}
+
+ // uninstall quote pack reverts the quote to what you had previously
+ if (data === 'marketplacequoteuninstall') {
+ this.init();
+ }
});
document.querySelector('.quote').style.fontSize = `${0.8 * Number((localStorage.getItem('zoomQuote') || 100) / 100)}em`;
diff --git a/src/modules/helpers/marketplace.js b/src/modules/helpers/marketplace.js
index 059503c6..3940059d 100644
--- a/src/modules/helpers/marketplace.js
+++ b/src/modules/helpers/marketplace.js
@@ -21,6 +21,9 @@ export default class MarketplaceFunctions {
case 'quotes':
localStorage.removeItem('quote_packs');
localStorage.removeItem('quoteAPI');
+ localStorage.setItem('quoteType', localStorage.getItem('oldQuoteType'));
+ localStorage.removeItem('oldQuoteType');
+ EventBus.dispatch('refresh', 'marketplacequoteuninstall');
break;
case 'photos':
localStorage.removeItem('photo_packs');
@@ -79,6 +82,9 @@ export default class MarketplaceFunctions {
}
localStorage.setItem('quote_packs', JSON.stringify(input.quotes));
+ localStorage.setItem('oldQuoteType', localStorage.getItem('quoteType'));
+ localStorage.setItem('quoteType', 'quote_pack');
+ EventBus.dispatch('refresh', 'quote');
break;
default:
break;