staff_data/apps/web/src/app/main/layout/MainHeader.tsx

105 lines
3.3 KiB
TypeScript
Raw Normal View History

2025-02-21 13:14:47 +08:00
import { Input, Layout, Avatar, Button, Dropdown } from "antd";
import {
EditFilled,
PlusOutlined,
SearchOutlined,
UserOutlined,
} from "@ant-design/icons";
2025-02-21 13:14:47 +08:00
import { useAuth } from "@web/src/providers/auth-provider";
2025-02-26 10:19:29 +08:00
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
2025-02-25 08:25:54 +08:00
import { UserMenu } from "./UserMenu/UserMenu";
2025-02-21 13:14:47 +08:00
import { NavigationMenu } from "./NavigationMenu";
2025-02-25 16:04:55 +08:00
import { useMainContext } from "./MainProvider";
import { Header } from "antd/es/layout/layout";
2025-02-06 16:32:31 +08:00
export function MainHeader() {
2025-02-21 13:14:47 +08:00
const { isAuthenticated, user } = useAuth();
2025-02-26 10:19:29 +08:00
const { id } = useParams();
2025-02-21 13:14:47 +08:00
const navigate = useNavigate();
2025-02-25 16:04:55 +08:00
const { searchValue, setSearchValue } = useMainContext();
2025-02-21 13:14:47 +08:00
return (
2025-02-27 19:31:48 +08:00
<div className="select-none w-full flex items-center justify-start bg-white shadow-md border-b border-gray-100 fixed z-30 py-2">
<div className="flex-1 px-4 md:px-6 mx-auto flex items-center justify-start h-full">
<div className="flex items-center justify-start space-x-4">
<img src="/logo.svg" className="h-8 w-auto " />
2025-02-21 13:14:47 +08:00
<div
onClick={() => navigate("/")}
className="text-2xl font-bold bg-gradient-to-r from-primary-600 via-primary-500 to-primary-400 bg-clip-text text-transparent hover:scale-105 transition-transform cursor-pointer">
</div>
<NavigationMenu />
</div>
2025-02-27 09:05:27 +08:00
</div>
2025-02-27 19:31:48 +08:00
<div className=" flex ">
2025-02-27 09:05:27 +08:00
<Input
size="large"
prefix={
<SearchOutlined className="text-gray-400 group-hover:text-blue-500 transition-colors" />
}
placeholder="搜索课程"
className="w-96 rounded-full"
value={searchValue}
2025-02-27 12:21:35 +08:00
onClick={(e) => {
if (!window.location.pathname.startsWith("/search")) {
navigate(`/search`);
window.scrollTo({
top: 0,
behavior: "smooth",
});
}
}}
2025-02-27 09:05:27 +08:00
onChange={(e) => setSearchValue(e.target.value)}
onPressEnter={(e) => {
2025-02-27 12:21:35 +08:00
if (!window.location.pathname.startsWith("/search")) {
navigate(`/search`);
2025-02-27 09:05:27 +08:00
window.scrollTo({
top: 0,
behavior: "smooth",
});
}
}}
/>
2025-02-27 19:31:48 +08:00
</div>
<div className="flex-1 flex justify-end gap-4 mr-2">
2025-02-27 09:05:27 +08:00
<div className="flex items-center gap-4">
2025-02-21 13:14:47 +08:00
{isAuthenticated && (
<>
<Button
2025-02-26 10:19:29 +08:00
onClick={() => {
const url = id
? `/course/${id}/editor`
: "/course/editor";
navigate(url);
}}
2025-02-21 13:14:47 +08:00
className="flex items-center space-x-1 bg-gradient-to-r from-blue-500 to-blue-600 text-white hover:from-blue-600 hover:to-blue-700 border-none shadow-md hover:shadow-lg transition-all"
icon={<EditFilled />}>
2025-02-26 10:19:29 +08:00
{id ? "编辑课程" : "创建课程"}
2025-02-21 13:14:47 +08:00
</Button>
</>
)}
2025-02-27 09:05:27 +08:00
{isAuthenticated && (
<Button
onClick={() => {
window.location.href = "/path/editor";
}}
icon={<PlusOutlined></PlusOutlined>}>
</Button>
)}
2025-02-21 13:14:47 +08:00
{isAuthenticated ? (
2025-02-25 08:25:54 +08:00
<UserMenu />
2025-02-21 13:14:47 +08:00
) : (
<Button
onClick={() => navigate("/login")}
className="flex items-center space-x-1 bg-gradient-to-r from-blue-500 to-blue-600 text-white hover:from-blue-600 hover:to-blue-700 border-none shadow-md hover:shadow-lg transition-all"
icon={<UserOutlined />}>
</Button>
)}
</div>
</div>
2025-02-26 23:18:14 +08:00
</div>
2025-02-21 13:14:47 +08:00
);
}