// SPDX-License-Identifier: MIT // Copyright (c) 2021 The Pybricks Authors import { Button, Classes, Drawer, FormGroup, Position, Switch, Tooltip, } from '@blueprintjs/core'; import { WithI18nProps, withI18n } from '@shopify/react-i18n'; import React from 'react'; import { connect } from 'react-redux'; import { Action, Dispatch } from '../actions'; import { closeSettings, openAboutDialog } from '../actions/app'; import { setBoolean } from '../actions/settings'; import { RootState } from '../reducers'; import { tooltipDelay } from '../settings/ui'; import { SettingId } from '../settings/user'; import { isMacOS } from '../utils/os'; import { SettingsStringId } from './settings-i18n'; import en from './settings-i18n.en.json'; type StateProps = { open: boolean; showDocs: boolean; darkMode: boolean; flashCurrentProgram: boolean; }; type DispatchProps = { onClose: () => void; onShowDocsChanged: (checked: boolean) => void; onDarkModeChanged: (checked: boolean) => void; onFlashCurrentProgramChanged: (checked: boolean) => void; onAbout: () => void; }; type SettingsProps = StateProps & DispatchProps & WithI18nProps; class SettingsDrawer extends React.PureComponent { render(): JSX.Element { const { i18n, open, onClose, showDocs, onShowDocsChanged, darkMode, onDarkModeChanged, flashCurrentProgram, onFlashCurrentProgramChanged, onAbout, } = this.props; return ( onClose()} >
{isMacOS() ? 'Cmd' : 'Ctrl'}-+, out: {isMacOS() ? 'Cmd' : 'Ctrl'}--, }, )} > onShowDocsChanged( (e.target as HTMLInputElement).checked, ) } /> onDarkModeChanged( (e.target as HTMLInputElement).checked, ) } /> onFlashCurrentProgramChanged( (e.target as HTMLInputElement).checked, ) } />
); } } const mapStateToProps = (state: RootState): StateProps => ({ open: state.app.showSettings, showDocs: state.settings.showDocs, darkMode: state.settings.darkMode, flashCurrentProgram: state.settings.flashCurrentProgram, }); const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ onClose: (): Action => dispatch(closeSettings()), onShowDocsChanged: (checked): Action => dispatch(setBoolean(SettingId.ShowDocs, checked)), onDarkModeChanged: (checked): Action => dispatch(setBoolean(SettingId.DarkMode, checked)), onFlashCurrentProgramChanged: (checked): Action => dispatch(setBoolean(SettingId.FlashCurrentProgram, checked)), onAbout: (): Action => dispatch(openAboutDialog()), }); export default connect( mapStateToProps, mapDispatchToProps, )( withI18n({ id: 'settings', fallback: en, translations: { en }, })(SettingsDrawer), );