diff --git a/src/App.jsx b/src/App.jsx index 2f4bb73e..82e7d636 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -4,6 +4,7 @@ import Background from './components/widgets/background/Background'; import Widgets from './components/widgets/Widgets'; import Modals from './components/modals/Modals'; +import EventBus from './modules/helpers/eventbus'; import SettingsFunctions from './modules/helpers/settings'; import { ToastContainer } from 'react-toastify'; @@ -15,6 +16,12 @@ export default class App extends React.PureComponent { } SettingsFunctions.loadSettings(); + + EventBus.on('refresh', (data) => { + if (data === 'other') { + SettingsFunctions.loadSettings(true); + } + }); } render() { diff --git a/src/components/modals/main/marketplace/sections/Marketplace.jsx b/src/components/modals/main/marketplace/sections/Marketplace.jsx index d5db4d9c..e21bef25 100644 --- a/src/components/modals/main/marketplace/sections/Marketplace.jsx +++ b/src/components/modals/main/marketplace/sections/Marketplace.jsx @@ -55,7 +55,7 @@ export default class Marketplace extends React.PureComponent { const installed = JSON.parse(localStorage.getItem('installed')); - if (installed.some(item => item.name === data)) { + if (installed.some(item => item.name === info.data.name)) { button = this.buttons.uninstall; } diff --git a/src/components/modals/main/scss/index.scss b/src/components/modals/main/scss/index.scss index bf964554..d332f3c4 100644 --- a/src/components/modals/main/scss/index.scss +++ b/src/components/modals/main/scss/index.scss @@ -16,7 +16,6 @@ opacity: 1; z-index: -2; padding: 25px; - transition: 0.6s; transition-timing-function: ease-in; border-radius: map-get($modal, 'border-radius'); -moz-user-select: none; diff --git a/src/components/modals/main/settings/Dropdown.jsx b/src/components/modals/main/settings/Dropdown.jsx index 12eb0a58..0fa10115 100644 --- a/src/components/modals/main/settings/Dropdown.jsx +++ b/src/components/modals/main/settings/Dropdown.jsx @@ -1,5 +1,7 @@ import React from 'react'; +import EventBus from '../../../../modules/helpers/eventbus'; + export default class Dropdown extends React.PureComponent { constructor(props) { super(props); @@ -26,6 +28,8 @@ export default class Dropdown extends React.PureComponent { if (this.props.onChange) { this.props.onChange(value); } + + EventBus.dispatch('refresh', this.props.category); } // todo: find a better way to do this diff --git a/src/components/modals/main/settings/Slider.jsx b/src/components/modals/main/settings/Slider.jsx index 79e34bab..372b2982 100644 --- a/src/components/modals/main/settings/Slider.jsx +++ b/src/components/modals/main/settings/Slider.jsx @@ -31,6 +31,7 @@ export default class Slider extends React.PureComponent { }); toast(this.language.toasts.reset); + EventBus.dispatch('refresh', this.props.category); } render() { diff --git a/src/components/modals/main/settings/Text.jsx b/src/components/modals/main/settings/Text.jsx index ab0b7f51..7140922a 100644 --- a/src/components/modals/main/settings/Text.jsx +++ b/src/components/modals/main/settings/Text.jsx @@ -36,6 +36,7 @@ export default class Text extends React.PureComponent { }); toast(this.language.toasts.reset); + EventBus.dispatch('refresh', this.props.category); } render() { diff --git a/src/components/modals/main/settings/sections/Advanced.jsx b/src/components/modals/main/settings/sections/Advanced.jsx index 732255f2..f0dd42fa 100644 --- a/src/components/modals/main/settings/sections/Advanced.jsx +++ b/src/components/modals/main/settings/sections/Advanced.jsx @@ -46,7 +46,7 @@ export default class AdvancedSettings extends React.PureComponent {

{advanced.customisation}

- +

{this.language.sections.experimental.title}

{advanced.experimental_warning}

diff --git a/src/components/modals/main/settings/sections/Appearance.jsx b/src/components/modals/main/settings/sections/Appearance.jsx index 833d2e7e..1b8bfc0c 100644 --- a/src/components/modals/main/settings/sections/Appearance.jsx +++ b/src/components/modals/main/settings/sections/Appearance.jsx @@ -29,7 +29,7 @@ export default function AppearanceSettings() { return ( <>

{appearance.title}

- +

{appearance.navbar.title}

diff --git a/src/components/modals/main/settings/sections/background/Background.jsx b/src/components/modals/main/settings/sections/background/Background.jsx index 379ae853..b6c914d5 100644 --- a/src/components/modals/main/settings/sections/background/Background.jsx +++ b/src/components/modals/main/settings/sections/background/Background.jsx @@ -30,7 +30,7 @@ export default class BackgroundSettings extends React.PureComponent { toast(this.language.toasts.reset); } - fileUpload(e) { + customBackground(e) { localStorage.setItem('customBackground', e.target.result); this.setState({ customBackground: e.target.result @@ -58,10 +58,6 @@ export default class BackgroundSettings extends React.PureComponent { } } - componentDidUpdate() { - localStorage.setItem('customBackground', this.state.customBackground); - } - async getBackgroundCategories() { const data = await (await fetch(window.constants.API_URL + '/images/categories')).json(); this.setState({ @@ -94,7 +90,7 @@ export default class BackgroundSettings extends React.PureComponent {

- + {this.state.backgroundCategories.map((category) => ( ))} @@ -106,9 +102,9 @@ export default class BackgroundSettings extends React.PureComponent { <>

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

    - this.setState({ customBackground: e.target.value })}> + this.customBackground(e)}> document.getElementById('bg-input').click()}>{background.source.upload} - this.fileUpload(e)} /> + this.customBackground(e)} />
{this.videoCustomSettings()} diff --git a/src/modules/helpers/eventbus.js b/src/modules/helpers/eventbus.js index 1c1d0313..898419bc 100644 --- a/src/modules/helpers/eventbus.js +++ b/src/modules/helpers/eventbus.js @@ -1,17 +1,15 @@ -const EventBus = { - on(event, callback) { +export default class EventBus { + static on(event, callback) { document.addEventListener(event, (e) => callback(e.detail)); - }, + } - dispatch(event, data) { + static dispatch(event, data) { document.dispatchEvent(new CustomEvent(event, { detail: data })); - }, + } - remove(event, callback) { + static remove(event, callback) { document.removeEventListener(event, callback); - }, -}; - -export default EventBus; \ No newline at end of file + } +} diff --git a/src/modules/helpers/marketplace.js b/src/modules/helpers/marketplace.js index 7d172ef5..648238d4 100644 --- a/src/modules/helpers/marketplace.js +++ b/src/modules/helpers/marketplace.js @@ -18,6 +18,7 @@ export default class MarketplaceFunctions { localStorage.removeItem('quote_packs'); localStorage.removeItem('quoteAPI'); break; + case 'photos': case 'photo_packs': localStorage.removeItem('photo_packs'); localStorage.setItem('backgroundType', localStorage.getItem('oldBackgroundType')); diff --git a/src/modules/helpers/settings.js b/src/modules/helpers/settings.js index 7b7dfebc..37bf9040 100644 --- a/src/modules/helpers/settings.js +++ b/src/modules/helpers/settings.js @@ -72,14 +72,15 @@ export default class SettingsFunctions { window.location.reload(); } - static loadSettings() { + static loadSettings(noeasteregg) { const css = localStorage.getItem('customcss'); if (css) { document.head.insertAdjacentHTML('beforeend', ''); } - if (localStorage.getItem('darkTheme') === 'true') { - document.getElementsByClassName('Toastify')[0].classList.add('dark'); + const js = localStorage.getItem('customjs'); + if (js) { + document.body.insertAdjacentHTML('beforeend', ''); } const font = localStorage.getItem('font'); @@ -118,24 +119,31 @@ export default class SettingsFunctions { } const widgetzoom = localStorage.getItem('widgetzoom'); - // don't bother if it's default zoom - if (widgetzoom !== '100') { - document.getElementById('root').style.zoom = widgetzoom + '%'; - } + document.getElementById('root').style.zoom = widgetzoom + '%'; const theme = localStorage.getItem('theme'); - if (theme === 'dark') { - document.body.classList.add('dark'); - } else if (theme === 'auto') { - // Set theme depending on user preferred - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + switch (theme) { + case 'dark': document.body.classList.add('dark'); - } + break; + case 'auto': + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + document.body.classList.add('dark'); + } + break; + default: + document.body.classList.remove('dark'); } const tabName = localStorage.getItem('tabName'); if (tabName !== window.language.tabname) { document.title = tabName; + } else { + document.title = window.language.tabname; + } + + if (noeasteregg === true) { + return; } // easter egg diff --git a/src/translations/de_DE.json b/src/translations/de_DE.json index 4e220d78..2982d412 100644 --- a/src/translations/de_DE.json +++ b/src/translations/de_DE.json @@ -1,4 +1,5 @@ { + "tabname": "Neuer Tab", "widgets": { "greeting": { "morning": "Guten Morgen", diff --git a/src/translations/en_GB.json b/src/translations/en_GB.json index 778d6daf..a8c941e8 100644 --- a/src/translations/en_GB.json +++ b/src/translations/en_GB.json @@ -122,6 +122,7 @@ "title": "Background", "ddg_proxy": "Use DuckDuckGo image proxy", "transition": "Fade-in transition", + "category": "Category", "buttons": { "title": "Buttons", "view": "Maximise",