mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-23 06:04:46 +08:00
feat: enhance workspace navigation menu with conditional rendering and mounted state
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
Settings2Icon,
|
Settings2Icon,
|
||||||
SettingsIcon,
|
SettingsIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@@ -30,29 +30,14 @@ import { useI18n } from "@/core/i18n/hooks";
|
|||||||
import { GithubIcon } from "./github-icon";
|
import { GithubIcon } from "./github-icon";
|
||||||
import { SettingsDialog } from "./settings";
|
import { SettingsDialog } from "./settings";
|
||||||
|
|
||||||
export function WorkspaceNavMenu() {
|
function NavMenuButtonContent({
|
||||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
isSidebarOpen,
|
||||||
const [settingsDefaultSection, setSettingsDefaultSection] = useState<
|
t,
|
||||||
"appearance" | "memory" | "tools" | "skills" | "notification" | "about"
|
}: {
|
||||||
>("appearance");
|
isSidebarOpen: boolean;
|
||||||
const { open: isSidebarOpen } = useSidebar();
|
t: ReturnType<typeof useI18n>["t"];
|
||||||
const { t } = useI18n();
|
}) {
|
||||||
return (
|
return isSidebarOpen ? (
|
||||||
<>
|
|
||||||
<SettingsDialog
|
|
||||||
open={settingsOpen}
|
|
||||||
onOpenChange={setSettingsOpen}
|
|
||||||
defaultSection={settingsDefaultSection}
|
|
||||||
/>
|
|
||||||
<SidebarMenu className="w-full">
|
|
||||||
<SidebarMenuItem>
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<SidebarMenuButton
|
|
||||||
size="lg"
|
|
||||||
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
|
||||||
>
|
|
||||||
{isSidebarOpen ? (
|
|
||||||
<div className="text-muted-foreground flex w-full items-center gap-2 text-left text-sm">
|
<div className="text-muted-foreground flex w-full items-center gap-2 text-left text-sm">
|
||||||
<SettingsIcon className="size-4" />
|
<SettingsIcon className="size-4" />
|
||||||
<span>{t.workspace.settingsAndMore}</span>
|
<span>{t.workspace.settingsAndMore}</span>
|
||||||
@@ -62,7 +47,39 @@ export function WorkspaceNavMenu() {
|
|||||||
<div className="flex size-full items-center justify-center">
|
<div className="flex size-full items-center justify-center">
|
||||||
<SettingsIcon className="text-muted-foreground size-4" />
|
<SettingsIcon className="text-muted-foreground size-4" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function WorkspaceNavMenu() {
|
||||||
|
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||||
|
const [settingsDefaultSection, setSettingsDefaultSection] = useState<
|
||||||
|
"appearance" | "memory" | "tools" | "skills" | "notification" | "about"
|
||||||
|
>("appearance");
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
const { open: isSidebarOpen } = useSidebar();
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SettingsDialog
|
||||||
|
open={settingsOpen}
|
||||||
|
onOpenChange={setSettingsOpen}
|
||||||
|
defaultSection={settingsDefaultSection}
|
||||||
|
/>
|
||||||
|
<SidebarMenu className="w-full">
|
||||||
|
<SidebarMenuItem>
|
||||||
|
{mounted ? (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<SidebarMenuButton
|
||||||
|
size="lg"
|
||||||
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
||||||
|
>
|
||||||
|
<NavMenuButtonContent isSidebarOpen={isSidebarOpen} t={t} />
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent
|
<DropdownMenuContent
|
||||||
@@ -131,6 +148,11 @@ export function WorkspaceNavMenu() {
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
|
) : (
|
||||||
|
<SidebarMenuButton size="lg" className="pointer-events-none">
|
||||||
|
<NavMenuButtonContent isSidebarOpen={isSidebarOpen} t={t} />
|
||||||
|
</SidebarMenuButton>
|
||||||
|
)}
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user