diff --git a/src/components/modals/main/scss/modules/_tab-content.scss b/src/components/modals/main/scss/modules/_tab-content.scss index 409bc46e..42f26e98 100644 --- a/src/components/modals/main/scss/modules/_tab-content.scss +++ b/src/components/modals/main/scss/modules/_tab-content.scss @@ -2,7 +2,8 @@ position: absolute; h3 { - text-transform: uppercase; + font-size: 1.5rem; + margin-bottom: 0; } } diff --git a/src/components/modals/main/settings/sections/background/Background.jsx b/src/components/modals/main/settings/sections/background/Background.jsx index dab0539a..1f7409ff 100644 --- a/src/components/modals/main/settings/sections/background/Background.jsx +++ b/src/components/modals/main/settings/sections/background/Background.jsx @@ -1,18 +1,14 @@ import variables from 'modules/variables'; -import { PureComponent, Fragment } from 'react'; -import { toast } from 'react-toastify'; -import { Cancel } from '@mui/icons-material'; +import { PureComponent } from 'react'; import Header from '../../Header'; import Checkbox from '../../Checkbox'; import Dropdown from '../../Dropdown'; -import FileUpload from '../../FileUpload'; import Slider from '../../Slider'; import Radio from '../../Radio'; import ColourSettings from './Colour'; - -import EventBus from 'modules/helpers/eventbus'; +import CustomSettings from './Custom'; export default class BackgroundSettings extends PureComponent { getMessage = (text) => variables.language.getMessage(variables.languagecode, text); @@ -20,93 +16,18 @@ export default class BackgroundSettings extends PureComponent { constructor() { super(); this.state = { - customBackground: this.getCustom(), backgroundType: localStorage.getItem('backgroundType') || 'api', backgroundCategories: [this.getMessage('modals.main.loading')] }; this.controller = new AbortController(); } - resetCustom = () => { - localStorage.setItem('customBackground', '[""]'); - this.setState({ - customBackground: [''] - }); - toast(this.getMessage('toasts.reset')); - EventBus.dispatch('refresh', 'background'); - } - - customBackground(e, text, index) { - const result = (text === true) ? e.target.value : e.target.result; - - const customBackground = this.state.customBackground; - customBackground[index] = result; - this.setState({ - customBackground - }); - this.forceUpdate(); - - localStorage.setItem('customBackground', JSON.stringify(customBackground)); - document.querySelector('.reminder-info').style.display = 'block'; - localStorage.setItem('showReminder', true); - } - - modifyCustomBackground(type, index) { - const customBackground = this.state.customBackground; - if (type === 'add') { - customBackground.push(''); - } else { - customBackground.splice(index, 1); - } - - this.setState({ - customBackground - }); - this.forceUpdate(); - - localStorage.setItem('customBackground', JSON.stringify(customBackground)); - } - - videoCustomSettings = (index) => { - const customBackground = this.state.customBackground[index]; - 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 ; } } - getCustom() { - let data; - try { - data = JSON.parse(localStorage.getItem('customBackground')); - } catch (e) { - data = [localStorage.getItem('customBackground')]; - } - - return data; - } - - uploadCustombackground(index) { - document.getElementById('bg-input').setAttribute('index', index); - document.getElementById('bg-input').click(); - // to fix loadFunction - this.setState({ - currentBackgroundIndex: index - }); - } - async getBackgroundCategories() { const data = await (await fetch(window.constants.API_URL + '/images/categories', { signal: this.controller.signal })).json(); @@ -190,28 +111,8 @@ export default class BackgroundSettings extends PureComponent { ); - const customSettings = ( - - ); - switch (this.state.backgroundType) { - case 'custom': backgroundSettings = customSettings; break; + case 'custom': backgroundSettings = ; break; case 'colour': backgroundSettings = ; break; default: backgroundSettings = APISettings; break; } diff --git a/src/components/modals/main/settings/sections/background/Custom.jsx b/src/components/modals/main/settings/sections/background/Custom.jsx new file mode 100644 index 00000000..b5207b24 --- /dev/null +++ b/src/components/modals/main/settings/sections/background/Custom.jsx @@ -0,0 +1,114 @@ +import variables from 'modules/variables'; +import { PureComponent, Fragment } from 'react'; +import { toast } from 'react-toastify'; +import { Cancel } from '@mui/icons-material'; + +import Checkbox from '../../Checkbox'; +import FileUpload from '../../FileUpload'; + +export default class CustomSettings extends PureComponent { + getMessage = (text) => variables.language.getMessage(variables.languagecode, text); + + constructor() { + super(); + this.state = { + customBackground: this.getCustom() + }; + } + + resetCustom = () => { + localStorage.setItem('customBackground', '[""]'); + this.setState({ + customBackground: [''] + }); + toast(this.getMessage('toasts.reset')); + EventBus.dispatch('refresh', 'background'); + } + + customBackground(e, text, index) { + const result = (text === true) ? e.target.value : e.target.result; + + const customBackground = this.state.customBackground; + customBackground[index] = result; + this.setState({ + customBackground + }); + this.forceUpdate(); + + localStorage.setItem('customBackground', JSON.stringify(customBackground)); + document.querySelector('.reminder-info').style.display = 'block'; + localStorage.setItem('showReminder', true); + } + + modifyCustomBackground(type, index) { + const customBackground = this.state.customBackground; + if (type === 'add') { + customBackground.push(''); + } else { + customBackground.splice(index, 1); + } + + this.setState({ + customBackground + }); + this.forceUpdate(); + + localStorage.setItem('customBackground', JSON.stringify(customBackground)); + } + + videoCustomSettings = (index) => { + const customBackground = this.state.customBackground[index]; + if (customBackground.startsWith('data:video/') || customBackground.endsWith('.mp4') || customBackground.endsWith('.webm') || customBackground.endsWith('.ogg')) { + return ( + <> + + + + ); + } else { + return null; + } + } + + getCustom() { + let data; + try { + data = JSON.parse(localStorage.getItem('customBackground')); + } catch (e) { + data = [localStorage.getItem('customBackground')]; + } + + return data; + } + + uploadCustombackground(index) { + document.getElementById('bg-input').setAttribute('index', index); + document.getElementById('bg-input').click(); + // to fix loadFunction + this.setState({ + currentBackgroundIndex: index + }); + } + + render() { + return ( +
    +

    {this.getMessage('modals.main.settings.sections.background.source.custom_background')} {this.getMessage('modals.main.settings.buttons.reset')}

    + {this.state.customBackground.map((_url, index) => ( + + this.customBackground(e, true, index)} autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'/> + {this.state.customBackground.length > 1 ? : null} + this.uploadCustombackground(index)}>{this.getMessage('modals.main.settings.sections.background.source.upload')} + {this.videoCustomSettings(index)} +

    +
    + ))} + + this.customBackground(e, false, this.state.currentBackgroundIndex)} /> + {this.props.interval} +
+ ); + } +}