11import React , { useState , useEffect } from 'react' ;
2+ import PropTypes from 'prop-types' ;
3+ import { userType , appTheme , toastConfig } from '@/types' ;
4+
25import {
36 BrowserRouter as Router ,
47 Route ,
@@ -16,18 +19,13 @@ import axios from 'axios';
1619import { connect } from 'react-redux' ;
1720import { bindActionCreators } from 'redux' ;
1821
19- // Error Boundary
2022import ErrorBoundary from '@/components/Errors/ErrorBoundary.jsx' ;
2123
22-
2324import { MuiThemeProvider } from '@material-ui/core/styles' ;
2425import { standard } from '@/config/themes' ;
25- import { WHITE_LIST_ROUTES } from './config/dataProperties' ;
26- // Requests imports
27- import { backendUrl } from './config/backend' ;
2826
27+ import { WHITE_LIST_ROUTES } from './config/dataProperties' ;
2928
30- // Redux imports
3129import { setUser as defineUser } from './redux/user/userActions' ;
3230import { setError as dispatchError } from './redux/error/errorActions' ;
3331import { setMenu as callMenu } from './redux/menu/menuActions' ;
@@ -50,15 +48,12 @@ import Users from './components/Users/Management/Users';
5048import UserForm from './components/Users/Management/UserForm' ;
5149import Categories from './components/Categories/Categories' ;
5250import CommentList from './components/Comments/CommentList' ;
53- import Articles from './pages/articles-section/Articles' ;
54- import Article from './pages/articles-section/Article' ;
55- import Stats from './pages/statistics-section/Stats' ;
51+ import Articles from './components/Articles/Articles' ;
52+ import Article from './components/Articles/Article/Article' ;
5653import MyAccount from './components/Users/MyAccount/MyAccount' ;
5754
58- // Css imports
5955import './index.css' ;
60- import { AppContent } from './styles' ;
61-
56+ import { AppContent , AppContainer } from './styles' ;
6257
6358function App ( props ) {
6459 const {
@@ -70,9 +65,9 @@ function App(props) {
7065 error,
7166 user,
7267 theme,
73- } = { ... props } ;
68+ } = props ;
7469
75- const appTheme = standard ( theme ) ;
70+ const themeConfig = standard ( user && user . _id ? theme : 'light' ) ;
7671
7772 const [ validatingToken , setValidatingToken ] = useState ( true ) ;
7873 const [ path , setPath ] = useState ( '' ) ;
@@ -106,7 +101,7 @@ function App(props) {
106101 const token = await JSON . parse ( localStorage . getItem ( 'user' ) ) ;
107102
108103 if ( token ) {
109- const url = ` ${ backendUrl } /auth/logged` ;
104+ const url = ' /auth/logged' ;
110105 await axios . post ( url , token ) . then ( ( res ) => {
111106 if ( res . data . user ) {
112107 setUser ( res . data ) ;
@@ -130,8 +125,8 @@ function App(props) {
130125 } , [ setMenu , setUser , setError , validatingToken ] ) ;
131126
132127 return (
133- < MuiThemeProvider theme = { appTheme } >
134- < Grid >
128+ < MuiThemeProvider theme = { themeConfig } >
129+ < AppContainer theme = { theme } >
135130 { ! validatingToken
136131 && (
137132 < Router >
@@ -151,7 +146,11 @@ function App(props) {
151146 { error
152147 && < Redirect to = "/error" />
153148 }
154- < AppContent user = { getPath ( ) === '/confirm-email' ? { } : user } isvalidating = { validatingToken ? 'true' : '' } >
149+ < AppContent
150+ user = { getPath ( ) === '/confirm-email' ? { } : user }
151+ isvalidating = { validatingToken ? 'true' : '' }
152+ theme = { theme }
153+ >
155154 < Switch >
156155 < Route path = "/" exact component = { Articles } />
157156 < Route path = "/auth" exact component = { Auth } />
@@ -163,16 +162,14 @@ function App(props) {
163162 < Route path = "/user" exact component = { UserForm } />
164163 < Route path = "/user/:id" exact component = { UserForm } />
165164 < Route path = "/users" exact component = { Users } />
166- < Route path = "/article" exact component = { Article } />
167- < Route path = "/article/:id" exact component = { Article } />
168165 < Route path = "/articles" exact component = { Articles } />
166+ < Route path = "/articles/:key" exact component = { Article } />
169167 < Route path = "/management" exact component = { Management } />
170168 < Route path = "/themes" exact component = { Themes } />
171169 < Route path = "/categories" exact component = { Categories } />
172170 < Route path = "/my-account" exact component = { MyAccount } />
173171 < Route path = "/comments" exact component = { CommentList } />
174172 < Route path = "/error" exact component = { Error } />
175- < Route path = "/stats" exact component = { Stats } />
176173 < Route component = { RouteNotFound } />
177174 </ Switch >
178175 </ AppContent >
@@ -189,11 +186,25 @@ function App(props) {
189186 </ Fade >
190187 )
191188 }
192- </ Grid >
189+ </ AppContainer >
193190 </ MuiThemeProvider >
194191 ) ;
195192}
196193
194+ App . propTypes = {
195+ user : userType . isRequired ,
196+ error : PropTypes . bool ,
197+ theme : appTheme . isRequired ,
198+ setMenu : PropTypes . func . isRequired ,
199+ setUser : PropTypes . func . isRequired ,
200+ setError : PropTypes . func . isRequired ,
201+ callToast : PropTypes . func . isRequired ,
202+ toast : toastConfig . isRequired ,
203+ } ;
204+
205+ App . defaultProps = {
206+ error : false ,
207+ } ;
197208
198209const mapStateToProps = ( state ) => ( {
199210 user : state . user ,
@@ -202,12 +213,12 @@ const mapStateToProps = (state) => ({
202213 toast : state . toast ,
203214 theme : state . theme ,
204215} ) ;
216+
205217const mapDispatchToProps = ( dispatch ) => bindActionCreators ( {
206218 setUser : defineUser ,
207219 setError : dispatchError ,
208220 setMenu : callMenu ,
209221 callToast : toastEmitter ,
210222} , dispatch ) ;
211223
212-
213224export default connect ( mapStateToProps , mapDispatchToProps ) ( App ) ;
0 commit comments