12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import {Component} from 'react';
- import ReactDOM from 'react-dom';
- import {cache} from '@emotion/css';
- import {CacheProvider, ThemeProvider} from '@emotion/react';
- import {loadPreferencesState} from 'app/actionCreators/preferences';
- import ConfigStore from 'app/stores/configStore';
- import GlobalStyles from 'app/styles/global';
- import {Config} from 'app/types';
- import {darkTheme, lightTheme, Theme} from 'app/utils/theme';
- import withConfig from 'app/utils/withConfig';
- type Props = {
- config: Config;
- };
- type State = {
- theme: Theme;
- };
- class Main extends Component<Props, State> {
- state: State = {
- theme: this.themeName === 'dark' ? darkTheme : lightTheme,
- };
- componentDidMount() {
- loadPreferencesState();
- }
- componentDidUpdate(prevProps: Props) {
- const {config} = this.props;
- if (config.theme !== prevProps.config.theme) {
-
- this.setState({
- theme: config.theme === 'dark' ? darkTheme : lightTheme,
- });
- }
- }
- get themeName() {
- return ConfigStore.get('theme');
- }
- render() {
- return (
- <ThemeProvider theme={this.state.theme}>
- <GlobalStyles
- isDark={this.props.config.theme === 'dark'}
- theme={this.state.theme}
- />
- <CacheProvider value={cache}>{this.props.children}</CacheProvider>
- {ReactDOM.createPortal(
- <meta name="color-scheme" content={this.themeName} />,
- document.head
- )}
- </ThemeProvider>
- );
- }
- }
- export default withConfig(Main);
|