import React from 'react'; import EventBus from '../../../../../../modules/helpers/eventbus'; import Checkbox from '../../Checkbox'; import Dropdown from '../../Dropdown'; import FileUpload from '../../FileUpload'; import Slider from '../../Slider'; import Switch from '../../Switch'; import Radio from '../../Radio'; import ColourSettings from './Colour'; import { toast } from 'react-toastify'; export default class BackgroundSettings extends React.PureComponent { constructor() { super(); this.state = { customBackground: localStorage.getItem('customBackground') || '', backgroundType: localStorage.getItem('backgroundType') || 'api', backgroundCategories: [window.language.modals.main.loading] }; this.language = window.language.modals.main.settings; this.controller = new AbortController(); } resetCustom = () => { localStorage.setItem('customBackground', ''); this.setState({ customBackground: '' }); toast(window.language.toasts.reset); EventBus.dispatch('refresh', 'background'); } customBackground(e, text) { const result = (text === true) ? e.target.value : e.target.result; localStorage.setItem('customBackground', result); this.setState({ customBackground: result }); EventBus.dispatch('refresh', 'background'); } videoCustomSettings = () => { const customBackground = this.state.customBackground; if (customBackground.startsWith('data:video/') || customBackground.endsWith('.mp4') || customBackground.endsWith('.webm') || customBackground.endsWith('.ogg')) { return ( <> ); } else { return null; } } marketplaceType = () => { if (localStorage.getItem('photo_packs')) { return ; } } async getBackgroundCategories() { const data = await (await fetch(window.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: [window.language.modals.update.offline.title] }); } this.getBackgroundCategories(); } componentWillUnmount() { // stop making requests this.controller.abort(); } render() { const { background } = this.language.sections; let backgroundSettings; const apiOptions = [ { name: 'Mue', value: 'mue' }, { name: 'Unsplash', value: 'unsplash' }, { name: 'Pexels', value: 'pexels' } ]; const APISettings = ( <>

{this.state.backgroundCategories.map((category) => ( ))}

); const customSettings = ( <>

    {background.source.custom_background} {this.language.buttons.reset}

    this.customBackground(e, true)}> document.getElementById('bg-input').click()}>{background.source.upload} this.customBackground(e)} />
{this.videoCustomSettings()} ); switch (this.state.backgroundType) { case 'custom': backgroundSettings = customSettings; break; case 'colour': backgroundSettings = ; break; default: backgroundSettings = APISettings; break; } return ( <>

{background.title}

{background.source.title}

this.setState({ backgroundType: value })} category='background'> {this.marketplaceType()}
{backgroundSettings}

{background.buttons.title}

{background.effects.title}



); } }