2
0
Fork 0

cherrypick gts's theme selector

This commit is contained in:
Ruben 2025-07-02 13:18:32 -05:00
commit cebd170b68
No known key found for this signature in database
GPG key ID: AE181294E97E4802
8 changed files with 73 additions and 18 deletions

View file

@ -26,9 +26,8 @@ const debouncedSave = debounce((dispatch, getState) => {
const data = getState().get('settings').filter((_, path) => path !== 'saved').toJS();
api().put('/api/web/settings', { data })
.then(() => dispatch({ type: SETTING_SAVE }))
.catch(error => dispatch(showAlertForError(error)));
localStorage.setItem('web_settings', JSON.stringify(data));
dispatch({ type: SETTING_SAVE });
}, 5000, { trailing: true });
export function saveSettings() {

View file

@ -20,6 +20,8 @@ import { IntlProvider } from 'flavours/glitch/locales';
import { store } from 'flavours/glitch/store';
import { isProduction } from 'flavours/glitch/utils/environment';
import { ThemeComponent } from './theme_component';
const title = isProduction() ? siteTitle : `${siteTitle} (Dev)`;
const hydrateAction = hydrateStore(initialState);
@ -58,15 +60,17 @@ export default class Mastodon extends PureComponent {
<IdentityContext.Provider value={this.identity}>
<IntlProvider>
<ReduxProvider store={store}>
<ErrorBoundary>
<Router>
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
<Route path='/' component={UI} />
</ScrollContext>
</Router>
<ThemeComponent>
<ErrorBoundary>
<Router>
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
<Route path='/' component={UI} />
</ScrollContext>
</Router>
<Helmet defaultTitle={title} titleTemplate={`%s - ${title}`} />
</ErrorBoundary>
<Helmet defaultTitle={title} titleTemplate={`%s - ${title}`} />
</ErrorBoundary>
</ThemeComponent>
</ReduxProvider>
</IntlProvider>
</IdentityContext.Provider>

View file

@ -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 !== '' ? <link rel='stylesheet' media='all' href={href} /> : null}
{children}
</>
);
};
ThemeComponent.propTypes = {
children: PropTypes.node,
};
export { ThemeComponent };

View file

@ -46,6 +46,19 @@ class LocalSettingsPage extends PureComponent {
({ intl, onChange, settings }) => (
<div className='glitch local-settings__page general'>
<h1><FormattedMessage id='settings.general' defaultMessage='General' /></h1>
<LocalSettingsPageItem
settings={settings}
item={['theme']}
id='mastodon-settings--theme'
options={[
{ value: 'mastodon-light', message: 'Light' },
{ value: 'mastodon', message: 'Dark' },
{ value: 'contrast', message: 'High contrast' },
]}
onChange={onChange}
>
<FormattedMessage id='settings.theme' defaultMessage='Theme' />
</LocalSettingsPageItem>
<LocalSettingsPageItem
settings={settings}
item={['show_reply_count']}