Skip to content

Commit

Permalink
fix: Hide moderator pages for casual users (#130)
Browse files Browse the repository at this point in the history
Hide image and product pages for non moderator users
  • Loading branch information
Valimp authored Dec 13, 2024
1 parent f2b862b commit 5818b51
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/components/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import LoginContext from '../contexts/login.tsx';


const pages = [
{ label: "Home", path: '/'},
{ label: "Images", path: '/image-moderation' },
{ label: "Product", path: '/moderation' },
{ label: "Home", path: '/', showtoUsers: ['moderator', 'user'] },
{ label: "Images", path: '/image-moderation', showtoUsers: ['moderator'] },
{ label: "Product", path: '/moderation', showtoUsers: ['moderator'] },
];
const settings = ['Logout'];

function ResponsiveAppBar() {

const { isLoggedIn } = useContext(LoginContext);
const { isLoggedIn, isModerator } = useContext(LoginContext);
const [anchorElNav, setAnchorElNav] = useState<null | HTMLElement>(null);
const [anchorElUser, setAnchorElUser] = useState<null | HTMLElement>(null);

Expand Down Expand Up @@ -60,6 +60,13 @@ function ResponsiveAppBar() {
window.location.reload();
}

const filteredPages = isLoggedIn
? pages.filter((page) =>
isModerator ? page.showtoUsers.includes('moderator') : page.showtoUsers.includes('user')
)
:
pages.filter((page) => page.showtoUsers.includes('user'));

return (
<AppBar position="static" sx={{backgroundColor: '#f2e9e4'}}>
<Container maxWidth="xl">
Expand Down Expand Up @@ -121,7 +128,7 @@ function ResponsiveAppBar() {
display: { xs: 'block', md: 'none' },
}}
>
{pages.map((page) => (
{filteredPages.map((page) => (
<Link to={page.path} key={page.label}>
<MenuItem onClick={handleCloseNavMenu}>
<Typography
Expand Down Expand Up @@ -169,7 +176,7 @@ function ResponsiveAppBar() {
NUTRIPATROL
</Typography>
<Box sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}>
{pages.map((page) => (
{filteredPages.map((page) => (
<Link to={page.path} key={page.label}>
<Button
onClick={handleCloseNavMenu}
Expand Down

0 comments on commit 5818b51

Please sign in to comment.