Experimental: add dark mode.

It's been ready for a while, though we haven't bothered enabling it because the
calendar view is less than great, though I think it makes sense to enable it
now as experimental and improve it as we go.

Fixes #128.
master
Tom Hacohen 5 years ago
parent f3a533ab2d
commit 435256bede

@ -40,18 +40,6 @@ import { credentialsSelector } from './login';
import { History } from 'history'; import { History } from 'history';
const muiTheme = createMuiTheme({
palette: {
primary: amber,
secondary: {
light: lightBlue.A200,
main: lightBlue.A400,
dark: lightBlue.A700,
contrastText: '#fff',
},
},
});
export const routeResolver = new RouteResolver({ export const routeResolver = new RouteResolver({
home: '', home: '',
pim: { pim: {
@ -179,6 +167,7 @@ class App extends React.PureComponent {
credentials: store.CredentialsData; credentials: store.CredentialsData;
entries: store.EntriesData; entries: store.EntriesData;
fetchCount: number; fetchCount: number;
darkMode: boolean;
errors: ImmutableList<Error>; errors: ImmutableList<Error>;
}; };
@ -197,6 +186,19 @@ class App extends React.PureComponent {
const errors = this.props.errors; const errors = this.props.errors;
const fetching = this.props.fetchCount > 0; const fetching = this.props.fetchCount > 0;
const muiTheme = createMuiTheme({
palette: {
type: this.props.darkMode ? 'dark' : undefined,
primary: amber,
secondary: {
light: lightBlue.A200,
main: lightBlue.A400,
dark: lightBlue.A700,
contrastText: '#fff',
},
},
});
const styles = { const styles = {
main: { main: {
backgroundColor: muiTheme.palette.background.default, backgroundColor: muiTheme.palette.background.default,
@ -283,6 +285,7 @@ const mapStateToProps = (state: store.StoreState) => {
credentials: credentialsSelector(state), credentials: credentialsSelector(state),
entries: state.cache.entries, entries: state.cache.entries,
fetchCount: state.fetchCount, fetchCount: state.fetchCount,
darkMode: !!state.settings.darkMode,
errors: state.errors, errors: state.errors,
}; };
}; };

@ -2,14 +2,17 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react'; import * as React from 'react';
import { useSelector } from 'react-redux'; import { useSelector, useDispatch } from 'react-redux';
import Select from '@material-ui/core/Select'; import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl'; import FormControl from '@material-ui/core/FormControl';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import FormGroup from '@material-ui/core/FormGroup';
import Switch from '@material-ui/core/Switch';
import InputLabel from '@material-ui/core/InputLabel'; import InputLabel from '@material-ui/core/InputLabel';
import { store, StoreState } from '../store'; import { StoreState } from '../store';
import { setSettings } from '../store/actions'; import { setSettings } from '../store/actions';
import Container from '../widgets/Container'; import Container from '../widgets/Container';
@ -36,13 +39,16 @@ function SecurityFingerprint() {
} }
export default React.memo(function Settings() { export default React.memo(function Settings() {
const dispatch = useDispatch();
const settings = useSelector((state: StoreState) => state.settings); const settings = useSelector((state: StoreState) => state.settings);
const darkMode = !!settings.darkMode;
function handleChange(event: React.ChangeEvent<any>) { function handleChange(event: React.ChangeEvent<any>) {
const name = event.target.name; const name = event.target.name;
const value = event.target.value; const value = event.target.value;
store.dispatch(setSettings({ ...settings, [name]: value })); dispatch(setSettings({ ...settings, [name]: value }));
} }
return ( return (
@ -65,6 +71,20 @@ export default React.memo(function Settings() {
<MenuItem value="en-us">English (United States)</MenuItem> <MenuItem value="en-us">English (United States)</MenuItem>
</Select> </Select>
</FormControl> </FormControl>
<h1>Experimental</h1>
<h2>Dark mode</h2>
<FormGroup>
<FormControlLabel
control={
<Switch
color="primary"
checked={darkMode}
onChange={() => dispatch(setSettings({ ...settings, darkMode: !darkMode }))}
/>
}
label="Dark mode"
/>
</FormGroup>
</Container> </Container>
</> </>
); );

@ -272,6 +272,7 @@ export const errorsReducer = handleActions(
// FIXME Move all the below (potentially the fetchCount ones too) to their own file // FIXME Move all the below (potentially the fetchCount ones too) to their own file
export interface SettingsType { export interface SettingsType {
locale: string; locale: string;
darkMode?: boolean;
taskSettings: { taskSettings: {
filterBy: string | null; filterBy: string | null;
sortBy: string; sortBy: string;
@ -286,6 +287,7 @@ export const settingsReducer = handleActions(
}, },
{ {
locale: 'en-gb', locale: 'en-gb',
darkMode: false,
taskSettings: { taskSettings: {
filterBy: null, filterBy: null,
sortBy: 'smart', sortBy: 'smart',

Loading…
Cancel
Save