diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js index fe9500d7..7da43b3e 100644 --- a/frontend/src/components/App.js +++ b/frontend/src/components/App.js @@ -21,23 +21,57 @@ export default class App extends Component { constructor(props) { super(props); this.state = { - dark: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches, expandedSettings: false, openLearn: false, - theme: { typography: { fontSize: 14 } }, + theme: createTheme({ + palette: { + mode: + window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches + ? 'dark' + : 'light', + background: { + default: + window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches + ? '#070707' + : '#fff', + }, + }, + }), }; } - lightTheme = createTheme({}); - - darkTheme = createTheme({ - palette: { - mode: 'dark', - background: { - default: '#070707', - }, - }, - }); + handleThemeChange = () => { + if (this.state.theme.palette.mode === 'light') { + this.setState(({ theme }) => ({ + theme: createTheme({ + typography: { + fontSize: theme.typography.fontSize, + }, + palette: { + mode: 'dark', + background: { + default: '#070707', + }, + }, + }), + })); + } + if (this.state.theme.palette.mode === 'dark') { + this.setState(({ theme }) => ({ + theme: createTheme({ + typography: { + fontSize: theme.typography.fontSize, + }, + palette: { + mode: 'light', + background: { + default: '#fff', + }, + }, + }), + })); + } + }; onSettingsClick = () => { this.setState({ @@ -62,7 +96,7 @@ export default class App extends Component { return ( - + this.setState({ dark: !this.state.dark })} + onClick={() => this.handleThemeChange()} > - {this.state.dark ? : } + {this.state.theme.palette.mode === 'dark' ? : }
- - - +