diff --git a/app/src/components/SettingsDrawer/BooleanSwitch.tsx b/app/src/components/SettingsDrawer/BooleanSwitch.tsx new file mode 100644 index 0000000..d0662c9 --- /dev/null +++ b/app/src/components/SettingsDrawer/BooleanSwitch.tsx @@ -0,0 +1,49 @@ +import * as React from 'react' +import { InputLabel, Switch, Tooltip, Theme } from '@material-ui/core' +import { withStyles } from '@material-ui/styles' +const sha1 = require('sha1') + +function BooleanSwitch(props: {title: string, value: boolean, tooltip: string, action: () => void, classes: any}) { + const { tooltip, value, action, title, classes } = props + + const clickHandler = (e: React.MouseEvent) => { + e.stopPropagation() + e.preventDefault() + action() + } + + return ( +
+ + + {title} + + + + + +
+ ) +} + +const styles = (theme: Theme) => ({ + switchBase: { + height: theme.spacing(4), + }, + label: { + flex: '1', + paddingTop: '8px', + }, +}) + +export default withStyles(styles)(BooleanSwitch) diff --git a/app/src/components/SettingsDrawer/Settings.tsx b/app/src/components/SettingsDrawer/Settings.tsx index fd03ec5..592a1f2 100644 --- a/app/src/components/SettingsDrawer/Settings.tsx +++ b/app/src/components/SettingsDrawer/Settings.tsx @@ -1,10 +1,11 @@ import * as React from 'react' +import BooleanSwitch from './BooleanSwitch' import BrokerStatistics from './BrokerStatistics' import ChevronRight from '@material-ui/icons/ChevronRight' import { AppState } from '../../reducers' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' -import { settingsActions } from '../../actions' +import { globalActions, settingsActions } from '../../actions' import { shell } from 'electron' import { StyleRulesCallback, withStyles } from '@material-ui/core/styles' import { TopicOrder } from '../../reducers/Settings' @@ -18,10 +19,8 @@ import { MenuItem, Select, Typography, - Switch, Tooltip, } from '@material-ui/core' -const sha1 = require('sha1') export const autoExpandLimitSet = [{ limit: 0, @@ -33,7 +32,7 @@ export const autoExpandLimitSet = [{ limit: 3, name: 'Some', }, { - limit: 10, + limit: 15, name: 'Most', }, { limit: 1E6, @@ -63,13 +62,13 @@ const styles: StyleRulesCallback = theme => ({ color: theme.palette.text.hint, cursor: 'pointer' as 'pointer', }, - switchBase: { - height: theme.spacing(4), - }, }) interface Props { - actions: typeof settingsActions + actions: { + settings: typeof settingsActions, + global: typeof globalActions, + } autoExpandLimit: number classes: any highlightTopicUpdates: boolean @@ -93,53 +92,20 @@ class Settings extends React.Component { private renderHighlightTopicUpdates() { const { highlightTopicUpdates, actions } = this.props - return this.renderSwitch('Show Activity', highlightTopicUpdates, actions.toggleHighlightTopicUpdates, 'Topics blink when a new message arrives') - } - - private renderSwitch(title: string, checked: boolean, action: any, tooltip: string) { - const { classes } = this.props - - const clickHandler = (e: React.MouseEvent) => { - e.stopPropagation() - e.preventDefault() - action() - } - - return ( -
- - - {title} - - - - - -
- ) + return } private selectTopicsOnMouseOver() { const { actions, selectTopicWithMouseOver } = this.props - const toggle = () => actions.selectTopicWithMouseOver(!selectTopicWithMouseOver) + const toggle = () => actions.settings.selectTopicWithMouseOver(!selectTopicWithMouseOver) - return this.renderSwitch('Quick Preview', selectTopicWithMouseOver, toggle, 'Select topics on mouse over') + return } private toggleTheme() { const { actions, theme } = this.props - return this.renderSwitch('Theme', theme === 'light', actions.toggleTheme, 'Select a theme') + return } private renderAutoExpand() { @@ -164,7 +130,7 @@ class Settings extends React.Component { } private onChangeAutoExpand = (e: React.ChangeEvent) => { - this.props.actions.setAutoExpandLimit(parseInt(e.target.value, 10)) + this.props.actions.settings.setAutoExpandLimit(parseInt(e.target.value, 10)) } private renderNodeOrder() { @@ -191,7 +157,7 @@ class Settings extends React.Component { } private onChangeSorting = (e: React.ChangeEvent) => { - this.props.actions.setTopicOrder(e.target.value as TopicOrder) + this.props.actions.settings.setTopicOrder(e.target.value as TopicOrder) } public render() { @@ -208,15 +174,15 @@ class Settings extends React.Component { tabIndex={0} role="button" > - - + Settings - - + + +
{this.renderAutoExpand()} {this.renderNodeOrder()} {this.renderHighlightTopicUpdates()} @@ -247,7 +213,10 @@ const mapStateToProps = (state: AppState) => { const mapDispatchToProps = (dispatch: any) => { return { - actions: bindActionCreators(settingsActions, dispatch), + actions: { + settings: bindActionCreators(settingsActions, dispatch), + global: bindActionCreators(globalActions, dispatch), + } } }