import React, { useState, useEffect } from 'react'; import { PropTypes } from 'prop-types'; import classNames from 'classnames'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { withStyles } from '@material-ui/core/styles'; import { Header, Sidebar, BreadCrumb } from 'ba-components'; import { toggleAction, openAction, playTransitionAction } from 'ba-actions/UiActions'; import { Fade } from '@material-ui/core'; import styles from './appStyles-jss'; function Dashboard(props) { const { classes, children, history, toggleDrawer, sidebarOpen, initialOpen, loadTransition, pageLoaded } = props; const [transform, setTransform] = useState(0); const darker = true; const handleScroll = () => { const doc = document.documentElement; const scroll = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); setTransform(scroll); }; useEffect(() => { // Scroll content to top window.addEventListener('scroll', handleScroll); // Set expanded sidebar menu const currentPath = history.location.pathname; initialOpen(currentPath); // Play page transition loadTransition(true); // Execute all arguments when page changes const unlisten = history.listen(() => { window.scrollTo(0, 0); setTimeout(() => { loadTransition(true); }, 500); }); return () => { unlisten(); }; }, []); return (