import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import { logout } from "../actions/authActions";
import senseboxLogo from "./sensebox_logo.svg";
import { withRouter } from "react-router-dom";
import withStyles from '@mui/styles/withStyles';
import Drawer from "@mui/material/Drawer";
import AppBar from "@mui/material/AppBar";
import Toolbar from "@mui/material/Toolbar";
import List from "@mui/material/List";
import Typography from "@mui/material/Typography";
import Divider from "@mui/material/Divider";
import IconButton from "@mui/material/IconButton";
import ListItem from "@mui/material/ListItem";
import ListItemIcon from "@mui/material/ListItemIcon";
import ListItemText from "@mui/material/ListItemText";
import LinearProgress from "@mui/material/LinearProgress";
import Tour from "reactour";
import { Badge } from "@mui/material";
import { home, assessment } from "./Tour";
import {
faBars,
faChevronLeft,
faLayerGroup,
faSignInAlt,
faSignOutAlt,
faUserCircle,
faQuestionCircle,
faCog,
faChalkboardTeacher,
faTools,
faLightbulb,
faCode,
faPuzzlePiece,
faUser,
faMicrochip,
faEarthEurope,
faEarthAmericas,
faCaretDown
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import * as Blockly from "blockly";
import Tooltip from "@mui/material/Tooltip";
import MenuItem from '@mui/material/MenuItem'
import Menu from '@mui/material/Menu'
import { setLanguage } from "../actions/generalActions";
import { setBoard } from "../actions/boardAction";
const styles = (theme) => ({
drawerWidth: {
// color: theme.palette.primary.main,
width: window.innerWidth < 600 ? "100%" : "240px",
borderRight: `1px solid ${theme.palette.primary.main}`,
},
appBarColor: {
backgroundColor: theme.palette.primary.main,
},
tourButton: {
marginleft: "auto",
marginright: "30px",
},
});
class Navbar extends Component {
constructor(props) {
super(props);
this.state = {
open: false,
isTourOpen: false,
anchorElLang: null,
anchorElBoard: null,
anchorElUser: null
};
}
toggleDrawer = () => {
this.setState({ open: !this.state.open });
};
openTour = () => {
this.setState({ isTourOpen: true });
};
closeTour = () => {
this.setState({ isTourOpen: false });
};
render() {
var isHome = /^\/(\/.*$|$)/g.test(this.props.location.pathname);
var isAssessment =
/^\/tutorial\/.{1,}$/g.test(this.props.location.pathname) &&
!this.props.tutorialIsLoading &&
this.props.tutorial &&
this.props.tutorial.steps[this.props.activeStep].type === "task";
return (
senseBox Blockly
{
this.props.selectedBoard === "mcu" ?
(
) : (
)
}
{
this.props.language === "en_US" ?
(
) : (
)
}
{isHome ? (
{
this.openTour();
}}
size="large">
) : null}
{isAssessment ? (
{
this.openTour();
}}
size="large">
) : null}
{
this.closeTour();
}}
/>
{this.props.user ? (
{ this.setState({ anchorElUser: event.target }) }}
style={{ margin: "0 30px 0 auto" }}
size="large"
sx={{ display: { xs: 'none', md: 'block' } }}
>
)
:
(
)
}
{Blockly.Msg.navbar_menu}
{[
{
text: Blockly.Msg.navbar_blockly,
icon: faPuzzlePiece,
link: "/",
},
{
text: Blockly.Msg.navbar_tutorials,
icon: faChalkboardTeacher,
link: "/tutorial",
},
{
text: Blockly.Msg.navbar_tutorialbuilder,
icon: faTools,
link: "/tutorial/builder",
restriction:
this.props.user &&
this.props.user.blocklyRole !== "user" &&
this.props.isAuthenticated,
},
{
text: Blockly.Msg.navbar_gallery,
icon: faLightbulb,
link: "/gallery",
},
{
text: Blockly.Msg.navbar_projects,
icon: faLayerGroup,
link: "/project",
restriction: this.props.isAuthenticated,
},
{
text: "Code Editor",
icon: faCode,
link: "/codeeditor",
},
].map((item, index) => {
if (
item.restriction ||
Object.keys(item).filter(
(attribute) => attribute === "restriction"
).length === 0
) {
return (
{item.text === "Code Editor" ? (
) : (
)}
);
} else {
return null;
}
})}
{[
{
text: Blockly.Msg.navbar_login,
icon: faSignInAlt,
link: "/user/login",
restriction: !this.props.isAuthenticated,
},
{
text: Blockly.Msg.navbar_account,
icon: faUserCircle,
link: "/user",
restriction: this.props.isAuthenticated,
},
{
text: Blockly.Msg.navbar_logout,
icon: faSignOutAlt,
function: this.props.logout,
restriction: this.props.isAuthenticated,
},
{ text: "FAQ", icon: faQuestionCircle, link: "/faq" },
{
text: Blockly.Msg.navbar_settings,
icon: faCog,
link: "/settings",
},
].map((item, index) => {
if (
item.restriction ||
Object.keys(item).filter(
(attribute) => attribute === "restriction"
).length === 0
) {
return (
{
item.function();
this.toggleDrawer();
}
: this.toggleDrawer
}
>
);
} else {
return null;
}
})}
{this.props.tutorialIsLoading || this.props.projectIsLoading ? (
) : null}
);
}
}
Navbar.propTypes = {
tutorialIsLoading: PropTypes.bool.isRequired,
projectIsLoading: PropTypes.bool.isRequired,
isAuthenticated: PropTypes.bool,
user: PropTypes.object,
tutorial: PropTypes.object,
activeStep: PropTypes.number.isRequired,
setLanguage: PropTypes.func.isRequired,
language: PropTypes.string.isRequired,
setBoard: PropTypes.func.isRequired,
selectedBoard: PropTypes.string.isRequired
};
const mapStateToProps = (state) => ({
tutorialIsLoading: state.tutorial.progress,
projectIsLoading: state.project.progress,
isAuthenticated: state.auth.isAuthenticated,
user: state.auth.user,
tutorial: state.tutorial.tutorials[0],
activeStep: state.tutorial.activeStep,
language: state.general.language,
selectedBoard: state.board.board
});
export default connect(mapStateToProps, { logout, setLanguage, setBoard })(
withStyles(styles, { withTheme: true })(withRouter(Navbar))
);