"use client" import React, { useState, useEffect } from "react" import { MenuItem } from "@/types/global" import Image from "next/image" import { cn } from "@/lib/utils" import ChatSidebar from "./components/ChatSidebar" import { Badge } from "../ui/badge" import Link from "next/link" import { usePathname, useRouter } from "next/navigation" import { useMainLayout } from "@/context/mainLayout" import { useCurrentUser } from "@/hooks/auth" import Notice from "./components/Notice" import useCreatorNavigation from "@/hooks/useCreatorNavigation" // 菜单项接口 interface IMenuItem { id: MenuItem icon: string selectedIcon: string label: string link: string isSelected: boolean } // 主侧边栏组件 function Sidebar() { const pathname = usePathname() const router = useRouter() const { isSidebarExpanded, dispatch } = useMainLayout(); const { data: user } = useCurrentUser(); const { routerToCreate } = useCreatorNavigation() // 在 /create/image 页面时强制收起侧边栏 const isImageCreatePage = ['/generate/image', '/generate/image-2-image', '/generate/image-edit', '/generate/image-2-background'].includes(pathname) const actualIsExpanded = isImageCreatePage ? false : isSidebarExpanded const menuItems: IMenuItem[] = [ { id: MenuItem.FOR_YOU, icon: "/icons/explore.svg", selectedIcon: "/icons/explore_selected.svg", label: "Home", link: '/', isSelected: pathname === '/', }, { id: MenuItem.CREATE, icon: "/icons/create.svg", selectedIcon: "/icons/create_selected.svg", label: "Create a Character", link: '/create', isSelected: pathname.startsWith('/create'), }, // { // id: MenuItem.EXPLORE, // icon: "/icons/explore.svg", // selectedIcon: "/icons/explore_selected.svg", // label: "Explore", // link: '/explore', // isSelected: pathname.startsWith('/explore'), // }, { id: MenuItem.CHAT, icon: "/icons/contact.svg", selectedIcon: "/icons/contact_selected.svg", label: "My Crushes", link: '/contact', isSelected: pathname.startsWith('/contact'), }, ] const toggleExpanded = () => { // 在 /create/image 页面时禁用展开功能 if (isImageCreatePage) return dispatch({ type: "updateState", payload: { isSidebarExpanded: !isSidebarExpanded, }, }) } return ( ) } export default Sidebar