sforkowany z mirror/soapbox
SoapboxConfig: add a default themeMode toggle
rodzic
93d2e83584
commit
3a0b58315f
|
@ -15,7 +15,7 @@ import { shortNumberFormat } from '../utils/numbers';
|
||||||
import { isStaff } from '../utils/accounts';
|
import { isStaff } from '../utils/accounts';
|
||||||
import { makeGetAccount } from '../selectors';
|
import { makeGetAccount } from '../selectors';
|
||||||
import { logOut } from 'soapbox/actions/auth';
|
import { logOut } from 'soapbox/actions/auth';
|
||||||
import ThemeToggle from '../features/ui/components/theme_toggle';
|
import ThemeToggle from '../features/ui/components/theme_toggle_container';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
||||||
|
|
|
@ -24,6 +24,8 @@ import { isMobile } from 'soapbox/is_mobile';
|
||||||
import detectPassiveEvents from 'detect-passive-events';
|
import detectPassiveEvents from 'detect-passive-events';
|
||||||
import Accordion from '../ui/components/accordion';
|
import Accordion from '../ui/components/accordion';
|
||||||
import SitePreview from './components/site_preview';
|
import SitePreview from './components/site_preview';
|
||||||
|
import ThemeToggle from 'soapbox/features/ui/components/theme_toggle';
|
||||||
|
import { defaultSettings } from 'soapbox/actions/settings';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.soapbox_config', defaultMessage: 'Soapbox config' },
|
heading: { id: 'column.soapbox_config', defaultMessage: 'Soapbox config' },
|
||||||
|
@ -186,6 +188,7 @@ class SoapboxConfig extends ImmutablePureComponent {
|
||||||
render() {
|
render() {
|
||||||
const { intl } = this.props;
|
const { intl } = this.props;
|
||||||
const soapbox = this.getSoapboxConfig();
|
const soapbox = this.getSoapboxConfig();
|
||||||
|
const settings = defaultSettings.mergeDeep(soapbox.get('defaultSettings'));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column icon='cog' heading={intl.formatMessage(messages.heading)} backBtnSlim>
|
<Column icon='cog' heading={intl.formatMessage(messages.heading)} backBtnSlim>
|
||||||
|
@ -201,6 +204,10 @@ class SoapboxConfig extends ImmutablePureComponent {
|
||||||
value={soapbox.get('brandColor')}
|
value={soapbox.get('brandColor')}
|
||||||
onChange={this.handleChange(['brandColor'], (e) => e.hex)}
|
onChange={this.handleChange(['brandColor'], (e) => e.hex)}
|
||||||
/>
|
/>
|
||||||
|
<ThemeToggle
|
||||||
|
onToggle={this.handleChange(['defaultSettings', 'themeMode'], value => value)}
|
||||||
|
settings={settings}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='fields-row__column fields-group fields-row__column-6'>
|
<div className='fields-row__column fields-group fields-row__column-6'>
|
||||||
<FileChooserLogo
|
<FileChooserLogo
|
||||||
|
|
|
@ -14,7 +14,7 @@ import ActionBar from 'soapbox/features/compose/components/action_bar';
|
||||||
import { openModal } from '../../../actions/modal';
|
import { openModal } from '../../../actions/modal';
|
||||||
import { openSidebar } from '../../../actions/sidebar';
|
import { openSidebar } from '../../../actions/sidebar';
|
||||||
import Icon from '../../../components/icon';
|
import Icon from '../../../components/icon';
|
||||||
import ThemeToggle from '../../ui/components/theme_toggle';
|
import ThemeToggle from '../../ui/components/theme_toggle_container';
|
||||||
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
import { isStaff } from 'soapbox/utils/accounts';
|
import { isStaff } from 'soapbox/utils/accounts';
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { injectIntl, defineMessages } from 'react-intl';
|
import { injectIntl, defineMessages } from 'react-intl';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import Icon from '../../../components/icon';
|
import Icon from '../../../components/icon';
|
||||||
import { changeSetting, getSettings } from 'soapbox/actions/settings';
|
|
||||||
import SettingToggle from '../../notifications/components/setting_toggle';
|
import SettingToggle from '../../notifications/components/setting_toggle';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
@ -12,31 +10,18 @@ const messages = defineMessages({
|
||||||
switchToDark: { id: 'tabs_bar.theme_toggle_dark', defaultMessage: 'Switch to dark theme' },
|
switchToDark: { id: 'tabs_bar.theme_toggle_dark', defaultMessage: 'Switch to dark theme' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
export default @injectIntl
|
||||||
return {
|
|
||||||
settings: getSettings(state),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
|
||||||
toggleTheme(setting) {
|
|
||||||
dispatch(changeSetting(['themeMode'], setting));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default @connect(mapStateToProps, mapDispatchToProps)
|
|
||||||
@injectIntl
|
|
||||||
class ThemeToggle extends React.PureComponent {
|
class ThemeToggle extends React.PureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
settings: ImmutablePropTypes.map.isRequired,
|
settings: ImmutablePropTypes.map.isRequired,
|
||||||
toggleTheme: PropTypes.func,
|
onToggle: PropTypes.func.isRequired,
|
||||||
showLabel: PropTypes.bool,
|
showLabel: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
handleToggleTheme = () => {
|
handleToggleTheme = () => {
|
||||||
this.props.toggleTheme(this.props.settings.get('themeMode') === 'light' ? 'dark' : 'light');
|
this.props.onToggle(this.props.settings.get('themeMode') === 'light' ? 'dark' : 'light');
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { changeSetting, getSettings } from 'soapbox/actions/settings';
|
||||||
|
import ThemeToggle from './theme_toggle';
|
||||||
|
|
||||||
|
const mapStateToProps = state => {
|
||||||
|
return {
|
||||||
|
settings: getSettings(state),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
onToggle(setting) {
|
||||||
|
dispatch(changeSetting(['themeMode'], setting));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(ThemeToggle);
|
Ładowanie…
Reference in New Issue