diff --git a/src/common/MenuLayout.js b/src/common/MenuLayout.js index 5c063ce6..0038e907 100644 --- a/src/common/MenuLayout.js +++ b/src/common/MenuLayout.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { Route, Switch } from 'react-router-dom'; import { Swipeable } from 'react-swipeable'; import { faBars as burgerIcon } from '@fortawesome/free-solid-svg-icons'; @@ -10,107 +10,76 @@ import MutedMessage from '../utils/MutedMessage'; import NotFound from './NotFound'; import './MenuLayout.scss'; -const MenuLayout = (TagsList, ShortUrls, AsideMenu, CreateShortUrl, ShortUrlVisits) => - class MenuLayout extends React.Component { - static propTypes = { - match: PropTypes.object, - selectServer: PropTypes.func, - location: PropTypes.object, - selectedServer: serverType, - }; +const propTypes = { + match: PropTypes.object, + selectServer: PropTypes.func, + location: PropTypes.object, + selectedServer: serverType, +}; - state = { showSideBar: false }; +const MenuLayout = (TagsList, ShortUrls, AsideMenu, CreateShortUrl, ShortUrlVisits) => { + const MenuLayoutComp = ({ match, location, selectedServer, selectServer }) => { + const [ showSideBar, setShowSidebar ] = useState(false); - componentDidMount() { - const { match, selectServer } = this.props; + useEffect(() => { const { params: { serverId } } = match; selectServer(serverId); + }, []); + useEffect(() => setShowSidebar(false), [ location ]); + + if (!selectedServer) { + return ; } - componentDidUpdate(prevProps) { - const { location } = this.props; - - // Hide sidebar when location changes - if (location !== prevProps.location) { - this.setState({ showSideBar: false }); - } - } - - render() { - const { selectedServer, match } = this.props; - - if (!selectedServer) { - return ; + const { params: { serverId } } = match; + const burgerClasses = classNames('menu-layout__burger-icon', { + 'menu-layout__burger-icon--active': showSideBar, + }); + const swipeMenuIfNoModalExists = (showSideBar) => () => { + if (document.querySelector('.modal')) { + return; } - const { params: { serverId } } = match; - const burgerClasses = classNames('menu-layout__burger-icon', { - 'menu-layout__burger-icon--active': this.state.showSideBar, - }); - const swipeMenuIfNoModalExists = (showSideBar) => () => { - if (document.querySelector('.modal')) { - return; - } + setShowSidebar(showSideBar); + }; - this.setState({ showSideBar }); - }; + return ( + + setShowSidebar(!showSideBar)} + /> - return ( - - this.setState(({ showSideBar }) => ({ showSideBar: !showSideBar }))} - /> - - - - - this.setState({ showSideBar: false })} - > - - - - - - } - /> - - + + + + setShowSidebar(false)}> + + + + + + } + /> + - - - ); - } + + + + ); }; + MenuLayoutComp.propTypes = propTypes; + + return MenuLayoutComp; +}; + export default MenuLayout;