2018-11-23 11:04:47 -08:00
|
|
|
// @flow
|
|
|
|
|
2019-02-08 21:02:03 -08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2018-11-23 10:41:50 -08:00
|
|
|
import { Provider } from 'react-redux';
|
2018-11-23 15:23:41 -08:00
|
|
|
import { ConnectedRouter } from 'connected-react-router';
|
2018-11-28 14:03:54 -08:00
|
|
|
import { ThemeProvider } from 'styled-components';
|
|
|
|
|
2018-11-28 06:06:29 -08:00
|
|
|
import { configureStore, history } from './redux/create';
|
2018-11-23 15:23:41 -08:00
|
|
|
import { Router } from './router/container';
|
2019-02-10 09:52:34 -08:00
|
|
|
import { appTheme as theme, GlobalStyle } from './theme';
|
2019-02-08 21:02:03 -08:00
|
|
|
import electronStore from '../config/electron-store';
|
2019-02-20 06:59:57 -08:00
|
|
|
import { DARK, LIGHT, THEME_MODE } from './constants/themes';
|
2018-11-23 10:41:50 -08:00
|
|
|
|
|
|
|
const store = configureStore({});
|
|
|
|
|
2019-02-08 21:02:03 -08:00
|
|
|
type Props = {};
|
|
|
|
type State = {
|
|
|
|
themeMode: string,
|
|
|
|
};
|
|
|
|
|
2019-02-20 06:59:57 -08:00
|
|
|
const getInitialTheme = () => {
|
|
|
|
const themeInStore = String(electronStore.get(THEME_MODE));
|
2019-05-27 14:31:07 -07:00
|
|
|
|
2019-02-20 06:59:57 -08:00
|
|
|
if (themeInStore === DARK || themeInStore === LIGHT) return themeInStore;
|
|
|
|
return DARK;
|
|
|
|
};
|
|
|
|
|
2019-02-08 21:02:03 -08:00
|
|
|
export class App extends Component<Props, State> {
|
|
|
|
state = {
|
2019-02-20 06:59:57 -08:00
|
|
|
themeMode: getInitialTheme(),
|
2019-02-08 21:02:03 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-02-20 06:59:57 -08:00
|
|
|
electronStore.set(THEME_MODE, getInitialTheme());
|
2019-02-08 21:02:03 -08:00
|
|
|
|
2019-02-10 09:52:34 -08:00
|
|
|
electronStore.onDidChange(THEME_MODE, newValue => this.setState({ themeMode: newValue }));
|
2019-02-08 21:02:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { themeMode } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ThemeProvider theme={{ ...theme, mode: themeMode }}>
|
|
|
|
<Fragment>
|
|
|
|
<GlobalStyle />
|
|
|
|
<Provider store={store}>
|
|
|
|
<ConnectedRouter history={history}>
|
|
|
|
<Router />
|
|
|
|
</ConnectedRouter>
|
|
|
|
</Provider>
|
|
|
|
</Fragment>
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|