diff --git a/src/features/background/options/Custom.jsx b/src/features/background/options/Custom.jsx index 7788f27e..7553aad4 100644 --- a/src/features/background/options/Custom.jsx +++ b/src/features/background/options/Custom.jsx @@ -41,14 +41,16 @@ export default class CustomSettings extends PureComponent { EventBus.emit('refresh', 'background'); }; - customBackground(e, text, index) { - const result = text === true ? e.target.value : e.target.result; + customBackground(e, index) { + const result = e.target.result; const customBackground = this.state.customBackground; - customBackground[index] = result; + customBackground[index || customBackground.length] = result; + this.setState({ customBackground, }); + this.forceUpdate(); localStorage.setItem('customBackground', JSON.stringify(customBackground)); @@ -159,7 +161,7 @@ export default class CustomSettings extends PureComponent { return toast(variables.getMessage('toasts.no_storage')); } - return this.customBackground(file, false, this.state.currentBackgroundIndex); + return this.customBackground(file, this.state.currentBackgroundIndex); } compressAccurately(file, { @@ -170,7 +172,11 @@ export default class CustomSettings extends PureComponent { return toast(variables.getMessage('toasts.no_storage')); } - this.customBackground(await filetoDataURL(res), false, this.state.currentBackgroundIndex); + this.customBackground({ + target: { + result: await filetoDataURL(res), + } + }, this.state.currentBackgroundIndex); }); e.preventDefault(); }; @@ -274,7 +280,7 @@ export default class CustomSettings extends PureComponent { this.customBackground(e, false, this.state.currentBackgroundIndex)} + loadFunction={(e) => this.customBackground(e, this.state.currentBackgroundIndex)} /> {this.videoCustomSettings()} { + async function getQuoteLanguages() { + const data = await (await fetch(variables.constants.API_URL + '/quotes/languages')).json(); - if (this.controller.signal.aborted === true) { - return; - } - - const quoteLanguages = data.map((language) => { - return { - name: languages.find((l) => l.value === language.name) - ? languages.find((l) => l.value === language.name).name - : 'English', - value: language, - }; - }); - - this.setState({ - quoteLanguages, - }); - } - - componentDidMount() { - if (navigator.onLine === false || localStorage.getItem('offlineMode') === 'true') { - return this.setState({ - quoteLanguages: [ - { - name: variables.getMessage('modals.main.marketplace.offline.description'), - value: 'loading', - }, - ], + const quoteLanguages = data.map((language) => { + return { + name: languages.find((l) => l.value === language.name) + ? languages.find((l) => l.value === language.name).name + : 'English', + value: language, + }; }); + + setQuoteLanguages(quoteLanguages); } - this.getquoteLanguages(); - } + getQuoteLanguages(); + }, []); - componentWillUnmount() { - // stop making requests - this.controller.abort(); - } - - render() { - return ( - <> -
- - {variables.getMessage('modals.main.settings.sections.language.title')} - -
- - Add translation - - -
-
-
- -
+ return ( + <> +
- {variables.getMessage('modals.main.settings.sections.language.quote')} + {variables.getMessage('modals.main.settings.sections.language.title')} -
- { - return { name: language.name, value: language.value.name }; - })} - defaultValue={this.state.quoteLanguages[0].name} - category="quote" - /> -
- - ); - } +
+ + Add translation + + +
+
+
+ +
+ + {variables.getMessage('modals.main.settings.sections.language.quote')} + +
+ { + return { name: language.name, value: language.value.name }; + })} + defaultValue={quoteLanguages[0].name} + category="quote" + /> +
+ + ); } export { LanguageOptions as default, LanguageOptions }; diff --git a/src/features/search/options/SearchOptions.jsx b/src/features/search/options/SearchOptions.jsx index 9f9b8932..94e31822 100644 --- a/src/features/search/options/SearchOptions.jsx +++ b/src/features/search/options/SearchOptions.jsx @@ -1,5 +1,5 @@ import variables from 'config/variables'; -import { PureComponent } from 'react'; +import { useState, useEffect } from 'react'; import { toast } from 'react-toastify'; import { TextField } from '@mui/material'; @@ -11,165 +11,152 @@ import EventBus from 'utils/eventbus'; import searchEngines from '../search_engines.json'; import defaults from './default'; -class SearchOptions extends PureComponent { - constructor() { - super(); - this.state = { - customEnabled: false, - customValue: localStorage.getItem('customSearchEngine') || defaults.customSearchEngine, - }; - } +function SearchOptions() { + const [customEnabled, setCustomEnabled] = useState(false); + const [customValue, setCustomValue] = useState( + localStorage.getItem('customSearchEngine') || defaults.customSearchEngine, + ); - resetSearch() { + function resetSearch() { localStorage.removeItem('customSearchEngine'); - this.setState({ - customValue: '', - }); + setCustomValue(''); toast(variables.getMessage('toasts.reset')); } - componentDidMount() { + useEffect(() => { if (localStorage.getItem('searchEngine') === 'custom') { - this.setState({ - customEnabled: true, - }); + setCustomEnabled(true); } else { localStorage.removeItem('customSearchEngine'); } - } + }, []); - componentDidUpdate() { - if (this.state.customEnabled === true && this.state.customValue !== '') { - localStorage.setItem('customSearchEngine', this.state.customValue); + useEffect(() => { + if (customEnabled === true && customValue !== '') { + localStorage.setItem('customSearchEngine', customValue); } EventBus.emit('refresh', 'search'); - } + }, [customEnabled, customValue]); - setSearchEngine(input) { + function setSearchEngine(input) { if (input === 'custom') { - this.setState({ - customEnabled: true, - }); + setCustomEnabled(true); } else { - this.setState({ - customEnabled: false, - }); + setCustomEnabled(false); localStorage.setItem('searchEngine', input); } EventBus.emit('refresh', 'search'); } - render() { - const SEARCH_SECTION = 'modals.main.settings.sections.search'; - - const AdditionalOptions = () => { - return ( - - - - {/* not supported on firefox */} - {navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined' ? ( - - ) : null} - - - - - - ); - }; - - const SearchEngineSelection = () => { - return ( - - - - this.setSearchEngine(value)} - items={[ - ...searchEngines.map((engine) => ({ - value: engine.settingsName, - text: engine.name, - })), - { - value: 'custom', - text: variables.getMessage(`${SEARCH_SECTION}.custom`), - }, - ]} - /> - - - ); - }; - - const CustomOptions = () => { - return ( - - - - this.setState({ customValue: e.target.value })} - varient="outlined" - InputLabelProps={{ shrink: true }} - /> -

- this.resetSearch()}> - {variables.getMessage('modals.main.settings.buttons.reset')} - -

-
-
- ); - }; + const SEARCH_SECTION = 'modals.main.settings.sections.search'; + const AdditionalOptions = () => { return ( - <> -
+ - - - - {this.state.customEnabled && CustomOptions()} - - + + {/* not supported on firefox */} + {navigator.userAgent.includes('Chrome') && typeof InstallTrigger === 'undefined' ? ( + + ) : null} + + + + + ); - } + }; + + const SearchEngineSelection = () => { + return ( + + + + setSearchEngine(value)} + items={[ + ...searchEngines.map((engine) => ({ + value: engine.settingsName, + text: engine.name, + })), + { + value: 'custom', + text: variables.getMessage(`${SEARCH_SECTION}.custom`), + }, + ]} + /> + + + ); + }; + + const CustomOptions = () => { + return ( + + + + setCustomValue(e.target.value)} + varient="outlined" + InputLabelProps={{ shrink: true }} + /> +

+ resetSearch()}> + {variables.getMessage('modals.main.settings.buttons.reset')} + +

+
+
+ ); + }; + + return ( + <> +
+ + + + {customEnabled && CustomOptions()} + + + ); } export { SearchOptions as default, SearchOptions };