Get theme from soapbox.json

This commit is contained in:
Alex Gleason 2020-06-01 00:49:43 -05:00
parent 3a7178300f
commit 3fc5d7a83c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 7 additions and 9 deletions

View file

@ -1,4 +1,6 @@
import api from '../api'; import api from '../api';
import { get } from 'lodash';
import { generateTheme } from 'soapbox/actions/theme';
export const SOAPBOX_CONFIG_IMPORT = 'SOAPBOX_CONFIG_IMPORT'; export const SOAPBOX_CONFIG_IMPORT = 'SOAPBOX_CONFIG_IMPORT';
export const SOAPBOX_CONFIG_FAIL = 'SOAPBOX_CONFIG_FAIL'; export const SOAPBOX_CONFIG_FAIL = 'SOAPBOX_CONFIG_FAIL';
@ -6,7 +8,9 @@ export const SOAPBOX_CONFIG_FAIL = 'SOAPBOX_CONFIG_FAIL';
export function fetchSoapboxConfig() { export function fetchSoapboxConfig() {
return (dispatch, getState) => { return (dispatch, getState) => {
api(getState).get('/instance/soapbox.json').then(response => { api(getState).get('/instance/soapbox.json').then(response => {
const { brandColor, mode } = get(response.data, 'theme');
dispatch(importSoapboxConfig(response.data)); dispatch(importSoapboxConfig(response.data));
dispatch(generateTheme(brandColor, mode));
}).catch(error => { }).catch(error => {
dispatch(soapboxConfigFail(error)); dispatch(soapboxConfigFail(error));
}); });

View file

@ -44,7 +44,6 @@ const mapStateToProps = (state) => {
return { return {
showIntroduction, showIntroduction,
me, me,
theme: settings.get('theme'),
reduceMotion: settings.get('reduceMotion'), reduceMotion: settings.get('reduceMotion'),
systemFont: settings.get('systemFont'), systemFont: settings.get('systemFont'),
dyslexicFont: settings.get('dyslexicFont'), dyslexicFont: settings.get('dyslexicFont'),
@ -60,7 +59,6 @@ class SoapboxMount extends React.PureComponent {
static propTypes = { static propTypes = {
showIntroduction: PropTypes.bool, showIntroduction: PropTypes.bool,
me: SoapboxPropTypes.me, me: SoapboxPropTypes.me,
theme: PropTypes.string,
reduceMotion: PropTypes.bool, reduceMotion: PropTypes.bool,
systemFont: PropTypes.bool, systemFont: PropTypes.bool,
dyslexicFont: PropTypes.bool, dyslexicFont: PropTypes.bool,
@ -70,12 +68,8 @@ class SoapboxMount extends React.PureComponent {
dispatch: PropTypes.func, dispatch: PropTypes.func,
}; };
componentDidMount() {
this.props.dispatch(generateTheme('#bb0000', 'light'));
}
render() { render() {
const { me, theme, themeCss, reduceMotion, systemFont, dyslexicFont, demetricator, locale } = this.props; const { me, themeCss, reduceMotion, systemFont, dyslexicFont, demetricator, locale } = this.props;
if (me === null) return null; if (me === null) return null;
const { localeData, messages } = getLocale(); const { localeData, messages } = getLocale();
@ -89,7 +83,6 @@ class SoapboxMount extends React.PureComponent {
// } // }
const bodyClass = classNames('app-body', { const bodyClass = classNames('app-body', {
[`theme-${theme}`]: theme,
'system-font': systemFont, 'system-font': systemFont,
'no-reduce-motion': !reduceMotion, 'no-reduce-motion': !reduceMotion,
'dyslexic': dyslexicFont, 'dyslexic': dyslexicFont,

View file

@ -32,7 +32,8 @@ const makeContrast = (percent, color, mode) => {
return brightness(percent, color); return brightness(percent, color);
}; };
export const generateTheme = (brandColor, mode) => { export const generateTheme = (brandColor, mode = 'light') => {
if (!brandColor) return modes.get(mode);
return modes.get(mode).merge(ImmutableMap({ return modes.get(mode).merge(ImmutableMap({
'brand-color': brandColor, 'brand-color': brandColor,
'accent-color': brightness(10, hue(-3, brandColor).hex).hex, 'accent-color': brightness(10, hue(-3, brandColor).hex).hex,