1+ import { useEffect } from 'react' ;
12import { BrowserRouter , Route , Switch } from 'react-router-dom' ;
3+ import 'external-svg-loader' ;
4+
5+ // Redux
6+ import { useDispatch , useSelector } from 'react-redux' ;
7+ import { bindActionCreators } from 'redux' ;
28import { autoLogin , getConfig } from './store/action-creators' ;
39import { actionCreators , store } from './store' ;
4- import 'external-svg-loader ';
10+ import { State } from './store/reducers ';
511
612// Utils
713import { checkVersion , decodeToken } from './utility' ;
@@ -12,9 +18,6 @@ import { Apps } from './components/Apps/Apps';
1218import { Settings } from './components/Settings/Settings' ;
1319import { Bookmarks } from './components/Bookmarks/Bookmarks' ;
1420import { NotificationCenter } from './components/NotificationCenter/NotificationCenter' ;
15- import { useDispatch } from 'react-redux' ;
16- import { bindActionCreators } from 'redux' ;
17- import { useEffect } from 'react' ;
1821
1922// Get config
2023store . dispatch < any > ( getConfig ( ) ) ;
@@ -25,6 +28,8 @@ if (localStorage.token) {
2528}
2629
2730export const App = ( ) : JSX . Element => {
31+ const { config, loading } = useSelector ( ( state : State ) => state . config ) ;
32+
2833 const dispath = useDispatch ( ) ;
2934 const { fetchQueries, setTheme, logout, createNotification } =
3035 bindActionCreators ( actionCreators , dispath ) ;
@@ -46,7 +51,7 @@ export const App = (): JSX.Element => {
4651 }
4752 } , 1000 ) ;
4853
49- // set theme
54+ // set user theme if present
5055 if ( localStorage . theme ) {
5156 setTheme ( localStorage . theme ) ;
5257 }
@@ -60,6 +65,13 @@ export const App = (): JSX.Element => {
6065 return ( ) => window . clearInterval ( tokenIsValid ) ;
6166 } , [ ] ) ;
6267
68+ // If there is no user theme, set the default one
69+ useEffect ( ( ) => {
70+ if ( ! loading && ! localStorage . theme ) {
71+ setTheme ( config . defaultTheme , false ) ;
72+ }
73+ } , [ loading ] ) ;
74+
6375 return (
6476 < >
6577 < BrowserRouter >
0 commit comments