From d05eede14f17e81a7918295f7262f775e7e60273 Mon Sep 17 00:00:00 2001 From: fbruc03 <65135023+fbruc03@users.noreply.github.com> Date: Thu, 12 Jan 2023 12:39:21 +0100 Subject: [PATCH 1/4] add new navbar --- package.json | 6 +- src/components/Navbar.js | 244 +++++++++++++++++++++++++++++++-------- 2 files changed, 200 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index 9ebe8f1..436e093 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "@blockly/zoom-to-fit": "^2.0.14", "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", - "@fortawesome/fontawesome-svg-core": "^1.2.36", - "@fortawesome/free-solid-svg-icons": "^5.15.4", - "@fortawesome/react-fontawesome": "^0.1.19", + "@fortawesome/fontawesome-svg-core": "^6.2.1", + "@fortawesome/free-solid-svg-icons": "^6.2.1", + "@fortawesome/react-fontawesome": "^0.2.0", "@monaco-editor/react": "^4.3.1", "@mui/lab": "^5.0.0-alpha.110", "@mui/material": "^5.10.16", diff --git a/src/components/Navbar.js b/src/components/Navbar.js index 9b03d76..f0fc14a 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -37,10 +37,18 @@ import { faLightbulb, faCode, faPuzzlePiece, + faUser, + faFlag, + faMicrochip, } 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"; +import { Redirect } from "react-router-dom"; const styles = (theme) => ({ drawerWidth: { @@ -63,6 +71,9 @@ class Navbar extends Component { this.state = { open: false, isTourOpen: false, + anchorElLang: null, + anchorElBoard: null, + anchorElUser: null }; } @@ -80,7 +91,6 @@ class Navbar extends Component { render() { var isHome = /^\/(\/.*$|$)/g.test(this.props.location.pathname); - var isTutorial = /^\/tutorial(\/.*$|$)/g.test(this.props.location.pathname); var isAssessment = /^\/tutorial\/.{1,}$/g.test(this.props.location.pathname) && !this.props.tutorialIsLoading && @@ -127,55 +137,189 @@ class Navbar extends Component { senseBox-Logo - {isTutorial ? ( - + { { this.setState({ anchorElLang: event.target }) }} + style={{ margin: "0 30px 0 auto" }} + size="large" + sx={{ display: { xs: 'none', md: 'block' } }} + > + + } + { + this.setState({ anchorElLang: null }); }} > - - Tutorial - - - ) : null} - {isHome ? ( - - { - this.openTour(); + { + this.props.setLanguage(event.currentTarget.getAttribute("value")); + this.setState({ anchorElLang: null }); }} - style={{ margin: "0 30px 0 auto" }} - size="large"> - - - - ) : null} - {isAssessment ? ( - - { - this.openTour(); + > + DE + + { + this.props.setLanguage(event.currentTarget.getAttribute("value")); + this.setState({ anchorElLang: null }); }} - style={{ margin: "0 30px 0 auto" }} - size="large"> - - - - ) : null} - { - this.closeTour(); - }} - /> + > + EN + + + { { this.setState({ anchorElBoard: event.target }) }} + style={{ margin: "0 30px 0 auto" }} + size="large" + sx={{ display: { xs: 'none', md: 'block' } }} + > + + } + { this.setState({ anchorElBoard: null }); }} + > + { + this.props.setBoard(event.currentTarget.getAttribute("value")); + this.setState({ anchorElBoard: null }); + }} + > + MCU + + { + this.props.setBoard(event.currentTarget.getAttribute("value")); + this.setState({ anchorElBoard: null }); + }} + > + MINI + + + {isHome ? ( + + { + this.openTour(); + }} + style={{ margin: "0 30px 0 auto" }} + size="large"> + + + + ) : null} + {isAssessment ? ( + + { + this.openTour(); + }} + style={{ margin: "0 30px 0 auto" }} + 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' } }} + > + + + { this.setState({ anchorElUser: null }); }} + > +
+

+ {this.props.user.name} +

+

+ {this.props.user.email} +

+
+
+ + + {Blockly.Msg.navbar_settings} + + + { + this.props.logout() + }} + > + {Blockly.Msg.navbar_logout} + +
+
+ ) + : + ( + + + + + ) + } + ({ @@ -378,8 +526,10 @@ const mapStateToProps = (state) => ({ 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 })( +export default connect(mapStateToProps, { logout, setLanguage, setBoard })( withStyles(styles, { withTheme: true })(withRouter(Navbar)) ); From 2c1594227ebf4d5f0b96118d0dd388ffa66fa816 Mon Sep 17 00:00:00 2001 From: fbruc03 <65135023+fbruc03@users.noreply.github.com> Date: Thu, 12 Jan 2023 22:30:41 +0100 Subject: [PATCH 2/4] style navbar items --- src/components/Navbar.js | 231 ++++++++++++++++++++++++--------------- 1 file changed, 144 insertions(+), 87 deletions(-) diff --git a/src/components/Navbar.js b/src/components/Navbar.js index f0fc14a..50d626f 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -38,8 +38,10 @@ import { faCode, faPuzzlePiece, faUser, - faFlag, faMicrochip, + faEarthEurope, + faEarthAmericas, + faCaretDown } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import * as Blockly from "blockly"; @@ -48,7 +50,6 @@ import MenuItem from '@mui/material/MenuItem' import Menu from '@mui/material/Menu' import { setLanguage } from "../actions/generalActions"; import { setBoard } from "../actions/boardAction"; -import { Redirect } from "react-router-dom"; const styles = (theme) => ({ drawerWidth: { @@ -138,92 +139,150 @@ class Navbar extends Component { senseBox-Logo
- { { this.setState({ anchorElLang: event.target }) }} - style={{ margin: "0 30px 0 auto" }} - size="large" - sx={{ display: { xs: 'none', md: 'block' } }} - > - - } - { - this.setState({ anchorElLang: null }); - }} - > - { - this.props.setLanguage(event.currentTarget.getAttribute("value")); - this.setState({ anchorElLang: null }); +
+ { + this.props.selectedBoard === "mcu" ? + ( + + ) : ( + + + ) + } + - DE - - { - this.props.setLanguage(event.currentTarget.getAttribute("value")); - this.setState({ anchorElLang: null }); + keepMounted + transformOrigin={{ + vertical: 'top', + horizontal: 'center', }} - > - EN - - - { { this.setState({ anchorElBoard: event.target }) }} - style={{ margin: "0 30px 0 auto" }} - size="large" - sx={{ display: { xs: 'none', md: 'block' } }} - > - - } - { this.setState({ anchorElBoard: null }); }} - > - { - this.props.setBoard(event.currentTarget.getAttribute("value")); + open={Boolean(this.state.anchorElBoard)} + onClose={() => { this.setState({ anchorElBoard: null }); }} > - MCU - - { - this.props.setBoard(event.currentTarget.getAttribute("value")); - this.setState({ anchorElBoard: null }); + { + this.props.setBoard(event.currentTarget.getAttribute("value")); + this.setState({ anchorElBoard: null }); + }} + > + MCU + + { + this.props.setBoard(event.currentTarget.getAttribute("value")); + this.setState({ anchorElBoard: null }); + }} + > + mini + + +
+
+ { + this.props.language === "en_US" ? + ( + + ) : ( + + + ) + } + { + this.setState({ anchorElLang: null }); }} > - MINI - - + { + this.props.setLanguage(event.currentTarget.getAttribute("value")); + this.setState({ anchorElLang: null }); + }} + > + Deutsch + + { + this.props.setLanguage(event.currentTarget.getAttribute("value")); + this.setState({ anchorElLang: null }); + }} + > + English + +
+
{isHome ? ( { this.openTour(); }} - style={{ margin: "0 30px 0 auto" }} size="large"> @@ -246,7 +304,6 @@ class Navbar extends Component { onClick={() => { this.openTour(); }} - style={{ margin: "0 30px 0 auto" }} size="large"> @@ -294,9 +351,9 @@ class Navbar extends Component {
- - {Blockly.Msg.navbar_settings} - + + {Blockly.Msg.navbar_settings} + { @@ -312,7 +369,7 @@ class Navbar extends Component { ( From e1b659cda5ae1df669c44960cef2c53f28307721 Mon Sep 17 00:00:00 2001 From: fbruc03 <65135023+fbruc03@users.noreply.github.com> Date: Thu, 12 Jan 2023 23:30:32 +0100 Subject: [PATCH 3/4] menu anchor always on button --- src/components/Navbar.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/Navbar.js b/src/components/Navbar.js index 50d626f..76105a6 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -69,6 +69,8 @@ const styles = (theme) => ({ class Navbar extends Component { constructor(props) { super(props); + this.langRef = React.createRef(); + this.mcuRef = React.createRef(); this.state = { open: false, isTourOpen: false, @@ -145,7 +147,10 @@ class Navbar extends Component { (