tianji/src/client/pages/Layout.tsx

97 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-08-31 16:11:47 +00:00
import React from 'react';
2023-10-08 11:06:59 +00:00
import { Outlet, useSearchParams } from 'react-router-dom';
2023-08-31 16:11:47 +00:00
import { NavItem } from '../components/NavItem';
import { UserOutlined } from '@ant-design/icons';
import { Button, Dropdown } from 'antd';
import { useUserStore } from '../store/user';
import { useLogout } from '../api/model/user';
2023-12-08 13:49:49 +00:00
import { ColorSchemeSwitcher } from '../components/ColorSchemeSwitcher';
2024-01-07 15:22:39 +00:00
import { version } from '../../shared';
2023-08-31 16:11:47 +00:00
export const Layout: React.FC = React.memo(() => {
2023-10-08 11:06:59 +00:00
const [params] = useSearchParams();
const workspaces = useUserStore((state) => {
const userInfo = state.info;
if (userInfo) {
return userInfo.workspaces.map((w) => ({
id: w.workspace.id,
name: w.workspace.name,
role: w.role,
current: userInfo.currentWorkspace?.id === w.workspace.id,
}));
}
return [];
});
const logout = useLogout();
2023-10-08 11:06:59 +00:00
const showHeader = !params.has('hideHeader');
2023-08-31 16:11:47 +00:00
return (
2023-12-08 13:49:49 +00:00
<div className="flex flex-col h-full dark:bg-gray-900 dark:text-gray-300">
2023-10-08 11:06:59 +00:00
{showHeader && (
2023-12-08 13:49:49 +00:00
<div className="flex items-center bg-gray-100 dark:bg-gray-800 px-4 sticky top-0 z-20">
2023-10-13 13:50:17 +00:00
<div className="px-2 mr-10 font-bold flex items-center">
<img src="/icon.svg" className="w-10 h-10 mr-2" />
2023-12-08 13:49:49 +00:00
<span className="text-xl dark:text-gray-200">Tianji</span>
2023-10-13 13:50:17 +00:00
</div>
2023-10-08 11:06:59 +00:00
<div className="flex gap-8">
<NavItem to="/dashboard" label="Dashboard" />
<NavItem to="/monitor" label="Monitor" />
<NavItem to="/website" label="Website" />
<NavItem to="/servers" label="Servers" />
<NavItem to="/settings" label="Settings" />
</div>
2023-08-31 16:11:47 +00:00
2023-10-08 11:06:59 +00:00
<div className="flex-1" />
2023-08-31 16:11:47 +00:00
2023-12-08 13:49:49 +00:00
<div className="flex gap-2">
<ColorSchemeSwitcher />
2023-10-08 11:06:59 +00:00
<Dropdown
placement="bottomRight"
menu={{
items: [
{
key: 'workspaces',
label: 'Workspaces',
children: workspaces.map((w) => ({
key: w.id,
label: `${w.name}${w.current ? '(current)' : ''}`,
disabled: w.current,
})),
},
{
key: 'logout',
label: 'Logout',
onClick: () => {
logout();
},
2023-10-08 11:06:59 +00:00
},
2024-01-07 15:22:39 +00:00
{
type: 'divider',
},
{
key: 'version',
label: `v${version}`,
disabled: true,
},
2023-10-08 11:06:59 +00:00
],
}}
>
<Button shape="circle" size="large" icon={<UserOutlined />} />
</Dropdown>
</div>
2023-08-31 16:11:47 +00:00
</div>
2023-10-08 11:06:59 +00:00
)}
<div className="flex-1 w-full overflow-hidden">
2023-12-12 11:19:50 +00:00
<div className="h-full px-1 sm:px-4 overflow-auto">
<div className="max-w-7xl m-auto">
<Outlet />
</div>
</div>
2023-08-31 16:11:47 +00:00
</div>
</div>
);
});
Layout.displayName = 'Layout';