Created
February 14, 2019 22:46
-
-
Save luismec90/cbe2818ced296891a64065e87ba8b507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
import { connect } from 'react-redux'; | |
import { ToastContainer, toast } from 'react-toastify'; | |
import { withRouter } from 'react-router-dom'; | |
import Navigation from './common/Navigation'; | |
import Sidebar from './common/Sidebar'; | |
import Footer from './common/Footer'; | |
import NProgress from 'nprogress'; | |
import TopBarProgress from 'react-topbar-progress-indicator'; | |
TopBarProgress.config({ | |
barColors: { | |
'0': '#BF6929', | |
'1.0': '#BF6929' | |
}, | |
shadowBlur: 5 | |
}); | |
function Main(props) { | |
const [show, setShow] = useState(false); | |
useEffect(() => { | |
if (window.message) { | |
toast.success(window.message); | |
window.message = ''; | |
} | |
}, []); | |
useEffect(() => { | |
const unListen = props.history.listen((location, action) => { | |
setShow(true); | |
console.log('setShow(true);'); | |
}); | |
return function cleanup() { | |
console.log('unListen'); | |
setShow(false); | |
unListen(); | |
console.log('setShow(false);'); | |
}; | |
}, []); | |
console.log({ show }); | |
return ( | |
<> | |
{show && <TopBarProgress />} | |
<ToastContainer | |
position="top-center" | |
autoClose={3000} | |
hideProgressBar={true} | |
newestOnTop={false} | |
closeOnClick={false} | |
rtl={false} | |
pauseOnVisibilityChange | |
draggable | |
pauseOnHover | |
/> | |
<div | |
className={ | |
props.isAuthenticated && props.user.isAdmin | |
? 'admin-authenticated' | |
: '' | |
} | |
> | |
<Navigation noHeader={props.noHeader} /> | |
{props.isAuthenticated && props.user.isAdmin && <Sidebar />} | |
<div className="main"> | |
<div className="row m-0"> | |
<div className="col-md-12">{props.children}</div> | |
</div> | |
<Footer /> | |
</div> | |
</div> | |
</> | |
); | |
} | |
const mapStateToProps = state => { | |
return { | |
isAuthenticated: state.Auth.isAuthenticated, | |
user: state.Auth.user | |
}; | |
}; | |
const connecter = connect(mapStateToProps); | |
export default withRouter(connecter(Main)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment