import variables from 'modules/variables'; import { PureComponent } from 'react'; import { MenuItem } from '@mui/material'; import { MdSource, MdOutlineKeyboardArrowRight, MdOutlineAutoAwesome, MdArrowBack, } from 'react-icons/md'; import Header from '../../Header'; import Checkbox from '../../Checkbox'; import Dropdown from '../../Dropdown'; import Slider from '../../Slider'; import Radio from '../../Radio'; import SettingsItem from '../../SettingsItem'; import Tooltip from '../../../../../helpers/tooltip/Tooltip'; import ColourSettings from './Colour'; import CustomSettings from './Custom'; import { values } from 'modules/helpers/settings/modals'; export default class BackgroundSettings extends PureComponent { getMessage = (text) => variables.language.getMessage(variables.languagecode, text); constructor() { super(); this.state = { backgroundType: localStorage.getItem('backgroundType') || 'api', backgroundFilter: localStorage.getItem('backgroundFilter') || 'none', backgroundCategories: [this.getMessage('modals.main.loading')], backgroundAPI: localStorage.getItem('backgroundAPI') || 'mue', marketplaceEnabled: localStorage.getItem('photo_packs'), effects: false, backgroundSettingsSection: false, }; this.controller = new AbortController(); } async getBackgroundCategories() { const data = await ( await fetch(variables.constants.API_URL + '/images/categories', { signal: this.controller.signal, }) ).json(); if (this.controller.signal.aborted === true) { return; } this.setState({ backgroundCategories: data, }); } componentDidMount() { if (navigator.onLine === false || localStorage.getItem('offlineMode') === 'true') { return this.setState({ backgroundCategories: [this.getMessage('modals.update.offline.title')], }); } this.getBackgroundCategories(); } componentWillUnmount() { // stop making requests this.controller.abort(); } render() { const { getMessage } = this; const interval = ( ); const APISettings = ( <> {this.state.backgroundCategories[0] === getMessage('modals.main.loading') ? ( <> {getMessage('modals.main.loading')} {getMessage('modals.main.loading')} ) : ( {this.state.backgroundCategories.map((category) => ( {category.charAt(0).toUpperCase() + category.slice(1)} ))} )} this.setState({ backgroundAPI: e })} /> {interval} ); let backgroundSettings = APISettings; switch (this.state.backgroundType) { case 'custom': backgroundSettings = ; break; case 'colour': backgroundSettings = ; break; case 'random_colour': case 'random_gradient': backgroundSettings = <>; break; default: break; } if ( localStorage.getItem('photo_packs') && this.state.backgroundType !== 'custom' && this.state.backgroundType !== 'colour' && this.state.backgroundType !== 'api' ) { backgroundSettings = null; } const usingImage = this.state.backgroundType !== 'colour' && this.state.backgroundType !== 'random_colour' && this.state.backgroundType !== 'random_gradient'; let header; if (this.state.effects === true) { header = ( this.setState({ effects: false })}> {getMessage('modals.main.settings.sections.background.title')}{' '} {' '} {getMessage('modals.main.settings.sections.background.effects.title')} ); } else if (this.state.backgroundSettingsSection === true) { header = ( this.setState({ backgroundSettingsSection: false })} > {getMessage('modals.main.settings.sections.background.title')}{' '} {' '} {getMessage('modals.main.settings.sections.background.source.title')} ); } else { header = (
); } return ( <> {header} {this.state.backgroundSettingsSection !== true && this.state.effects !== true ? ( <>
this.setState({ backgroundSettingsSection: true })} >
{getMessage('modals.main.settings.sections.background.source.title')} Select where to get background images from
this.setState({ backgroundType: value })} category="background" > {this.state.marketplaceEnabled ? ( ) : null}
this.setState({ effects: true })}>
{getMessage('modals.main.settings.sections.background.effects.title')} Add effects to the background image
{' '}
) : null} {this.state.backgroundSettingsSection !== true && this.state.effects !== true ? ( ) : null} {this.state.backgroundSettingsSection ? ( <> this.setState({ backgroundType: value })} category="background" > {this.state.marketplaceEnabled ? ( ) : null} {backgroundSettings} ) : null} {(this.state.backgroundType === 'api' || this.state.backgroundType === 'custom' || this.state.marketplaceEnabled) && this.state.effects ? ( this.setState({ backgroundFilter: value })} category="background" element="#backgroundImage" > {this.state.backgroundFilter !== 'none' ? ( ) : null} ) : null} ); } }