Files
fredy/ui/src/components/navigation/Navigation.jsx

89 lines
2.6 KiB
React
Raw Normal View History

2025-12-11 10:40:55 +01:00
/*
* Copyright (c) 2026 by Christian Kellner.
2025-12-11 10:40:55 +01:00
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
*/
2025-12-14 12:23:59 +01:00
import React, { useEffect, useState } from 'react';
import { Button, Nav } from '@douyinfe/semi-ui';
import { IconStar, IconSetting, IconTerminal, IconHistogram, IconSidebar } from '@douyinfe/semi-icons';
import logoWhite from '../../assets/logo_white.png';
2025-12-14 12:23:59 +01:00
import heart from '../../assets/heart.png';
import Logout from '../logout/Logout.jsx';
import { useLocation, useNavigate } from 'react-router-dom';
import './Navigate.less';
import { useFeature } from '../../hooks/featureHook.js';
2025-12-14 12:23:59 +01:00
import { useScreenWidth } from '../../hooks/screenWidth.js';
export default function Navigation({ isAdmin }) {
const navigate = useNavigate();
const location = useLocation();
const width = useScreenWidth();
2025-12-14 12:23:59 +01:00
const [collapsed, setCollapsed] = useState(width <= 850);
const watchlistFeature = useFeature('WATCHLIST_MANAGEMENT') || false;
2025-12-14 12:23:59 +01:00
useEffect(() => {
if (width <= 850) {
setCollapsed(true);
}
}, [width]);
const items = [
2025-12-14 12:23:59 +01:00
{ itemKey: '/dashboard', text: 'Dashboard', icon: <IconHistogram /> },
{ itemKey: '/jobs', text: 'Jobs', icon: <IconTerminal /> },
{
itemKey: 'listings',
text: 'Listings',
icon: <IconStar />,
items: [
{ itemKey: '/listings', text: 'Overview' },
{ itemKey: '/map', text: 'Map View' },
],
},
];
if (isAdmin) {
const settingsItems = [
{ itemKey: '/users', text: 'User Management' },
{ itemKey: '/generalSettings', text: 'General Settings' },
];
if (watchlistFeature) {
settingsItems.push({ itemKey: '/watchlistManagement', text: 'Watchlist Management' });
}
items.push({
itemKey: 'settings',
text: 'Settings',
icon: <IconSetting />,
items: settingsItems,
});
}
function parsePathName(name) {
const split = name.split('/').filter((s) => s.length !== 0);
return '/' + split[0];
}
return (
<Nav
2025-12-14 12:23:59 +01:00
style={{ height: '100%' }}
items={items}
isCollapsed={collapsed}
selectedKeys={[parsePathName(location.pathname)]}
onSelect={(key) => {
navigate(key.itemKey);
}}
2025-12-14 12:23:59 +01:00
header={<img src={collapsed ? heart : logoWhite} width={collapsed ? '80' : '160'} alt="Fredy Logo" />}
footer={
2025-12-14 12:23:59 +01:00
<Nav.Footer className="navigate__footer">
<Logout text={!collapsed} />
2025-12-14 12:23:59 +01:00
<Button icon={<IconSidebar />} onClick={() => setCollapsed(!collapsed)}>
{!collapsed && 'Collapse'}
</Button>
</Nav.Footer>
}
/>
);
}