From 8bef4f04c2b0b203450fe5753b6109a0b0d04e82 Mon Sep 17 00:00:00 2001 From: ditoaugusta Date: Fri, 27 Mar 2020 17:39:49 +0700 Subject: exp: hooks (1) --- modern/src/MainToolbar.js | 147 ++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 84 deletions(-) (limited to 'modern/src/MainToolbar.js') diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js index 6e2e4d6..9ec89a2 100644 --- a/modern/src/MainToolbar.js +++ b/modern/src/MainToolbar.js @@ -1,5 +1,6 @@ -import React, { Component, Fragment } from 'react'; -import { withStyles } from '@material-ui/core/styles'; +import React, { useState } from 'react'; +import { useHistory } from 'react-router-dom'; +import { makeStyles } from '@material-ui/core/styles'; import AppBar from '@material-ui/core/AppBar'; import Toolbar from '@material-ui/core/Toolbar'; import Typography from '@material-ui/core/Typography'; @@ -16,7 +17,7 @@ import DashboardIcon from '@material-ui/icons/Dashboard'; import BarChartIcon from '@material-ui/icons/BarChart'; import SettingsIcon from '@material-ui/icons/Settings'; -const styles = theme => ({ +const useStyles = makeStyles(theme => ({ flex: { flexGrow: 1 }, @@ -30,94 +31,72 @@ const styles = theme => ({ marginLeft: -12, marginRight: 20, } -}); +})); -class MainToobar extends Component { - constructor(props) { - super(props); - this.state = { - drawer: false - }; - this.openDrawer = this.openDrawer.bind(this); - this.closeDrawer = this.closeDrawer.bind(this); - this.handleLogout = this.handleLogout.bind(this); - } - - openDrawer() { - this.setState({ - drawer: true - }); - }; +const MainToolbar = () => { + const [drawer, setDrawer] = useState(false); + const classes = useStyles(); + const history = useHistory(); - closeDrawer() { - this.setState({ - drawer: false - }); - }; + const openDrawer = () => { setDrawer(true) } + const closeDrawer = () => { setDrawer(false) } - handleLogout() { - fetch("/api/session", { - method: "DELETE" - }).then(response => { + const handleLogout = () => { + fetch('/api/session', { method: 'DELETE' }).then(response => { if (response.ok) { - this.props.history.push('/login'); + history.push('/login'); } - }); + }) } - render() { - const { classes } = this.props; - return ( - - - - - - - - Traccar + return (<> + + + + + + + Traccar - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
-
-
- ); - } + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ ); } -export default withStyles(styles)(MainToobar); +export default MainToolbar; -- cgit v1.2.3