From ba53e0335cf5834d74700df5a06981d8ee0b1e71 Mon Sep 17 00:00:00 2001 From: tobi Date: Sat, 21 Dec 2024 15:26:14 +0100 Subject: [PATCH] [feature] Add theme selector to app settings --- .../flavours/glitch/containers/mastodon.jsx | 20 ++++++----- .../glitch/containers/theme_component.jsx | 36 +++++++++++++++++++ .../features/local_settings/page/index.jsx | 13 +++++++ .../glitch/reducers/local_settings.js | 1 + 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 app/javascript/flavours/glitch/containers/theme_component.jsx diff --git a/app/javascript/flavours/glitch/containers/mastodon.jsx b/app/javascript/flavours/glitch/containers/mastodon.jsx index 1ab20d022..426c551f7 100644 --- a/app/javascript/flavours/glitch/containers/mastodon.jsx +++ b/app/javascript/flavours/glitch/containers/mastodon.jsx @@ -19,6 +19,8 @@ import initialState, { title as siteTitle } from 'flavours/glitch/initial_state' import { IntlProvider } from 'flavours/glitch/locales'; import { store } from 'flavours/glitch/store'; +import { ThemeComponent } from './theme_component'; + const title = process.env.NODE_ENV === 'production' ? siteTitle : `${siteTitle} (Dev)`; const hydrateAction = hydrateStore(initialState); @@ -79,15 +81,17 @@ export default class Mastodon extends PureComponent { return ( - - - - - - + + + + + + + - - + + + ); diff --git a/app/javascript/flavours/glitch/containers/theme_component.jsx b/app/javascript/flavours/glitch/containers/theme_component.jsx new file mode 100644 index 000000000..4c9bda60c --- /dev/null +++ b/app/javascript/flavours/glitch/containers/theme_component.jsx @@ -0,0 +1,36 @@ +import PropTypes from 'prop-types'; +import React from 'react'; + +import { useAppSelector } from 'flavours/glitch/store'; + +const ThemeComponent = ({ children }) => { + const theme = useAppSelector( + (state) => state.getIn(['local_settings', 'theme']) ?? 'mastodon-light', + ); + + let href; + switch (true) { + case theme === 'mastodon': + href = ''; + break; + case theme === 'mastodon-light': + href = '/packs/css/skins/glitch/mastodon-light/common.css'; + break; + case theme === 'contrast': + href = '/packs/css/skins/glitch/contrast/common.css'; + break; + } + + return ( + <> + {href !== '' ? : null} + {children} + + ); +}; + +ThemeComponent.propTypes = { + children: PropTypes.node, +}; + +export { ThemeComponent }; diff --git a/app/javascript/flavours/glitch/features/local_settings/page/index.jsx b/app/javascript/flavours/glitch/features/local_settings/page/index.jsx index ca2a4673c..d8e6d6a26 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/index.jsx +++ b/app/javascript/flavours/glitch/features/local_settings/page/index.jsx @@ -52,6 +52,19 @@ class LocalSettingsPage extends PureComponent { ({ intl, onChange, settings }) => (

+ + + state.mergeDeep(localSettings);