Skip to content

Commit

Permalink
The language can NOT be changed when /questions
Browse files Browse the repository at this point in the history
  • Loading branch information
lauratbg committed Apr 26, 2024
1 parent 3c33895 commit 96bf3a8
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions webapp/src/components/fragments/NavBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import MenuItem from '@mui/material/MenuItem';
import Menu from '@mui/material/Menu';
import "../../custom.css";
Expand All @@ -10,6 +10,7 @@ import Cookies from 'js-cookie';

function Navbar() {
const navigate = useNavigate();
const location = useLocation();
const [t, i18n] = useTranslation("global");
const [anchorLanguage, setAnchorLanguage] = useState(null);
const [anchorUser, setAnchorUser] = useState(null);
Expand Down Expand Up @@ -41,16 +42,21 @@ function Navbar() {
handleLanguageMenuClose();
};

const isQuestionsPage = location.pathname === '/questions';

return (
<div className="navbar-container">
<div className='left-nav'>
<Profile />
<Link to="/home" className="home-button">
<h1 className='navbar-text'>{t("navBar.title")}</h1>
</Link>
<Profile />
<Link to="/home" className="home-button">
<h1 className='navbar-text'>{t("navBar.title")}</h1>
</Link>
</div>
<div className='right-nav'>
<button className="language-button" onClick={handleLanguageMenuOpen}>{t("navBar.language")}</button>
{/* If /questions, disable button*/}
{!isQuestionsPage && (
<button className="language-button" onClick={handleLanguageMenuOpen}>{t("navBar.language")}</button>
)}
<Menu
anchorEl={anchorLanguage}
open={Boolean(anchorLanguage)}
Expand All @@ -65,18 +71,17 @@ function Navbar() {

{Cookies.get('user') ? (
<>
<button className="user-button" onClick={handleUserMenuOpen}>{ JSON.parse(Cookies.get('user')).username}</button>
<Menu
anchorEl={anchorUser}
open={Boolean(anchorUser)}
onClose={handleUserMenuClose}
disableAutoFocusItem
>
<MenuItem id="logout" onClick={() => removeCookie()}> {t("navBar.logout")}</MenuItem>
</Menu>
<button className="user-button" onClick={handleUserMenuOpen}>{ JSON.parse(Cookies.get('user')).username}</button>
<Menu
anchorEl={anchorUser}
open={Boolean(anchorUser)}
onClose={handleUserMenuClose}
disableAutoFocusItem
>
<MenuItem id="logout" onClick={() => removeCookie()}> {t("navBar.logout")}</MenuItem>
</Menu>
</>
) : null}

</div>
</div>
);
Expand Down

0 comments on commit 96bf3a8

Please sign in to comment.