mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-18 12:04:45 +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,13 +30,39 @@ import { useI18n } from "@/core/i18n/hooks";
|
|||||||
import { GithubIcon } from "./github-icon";
|
import { GithubIcon } from "./github-icon";
|
||||||
import { SettingsDialog } from "./settings";
|
import { SettingsDialog } from "./settings";
|
||||||
|
|
||||||
|
function NavMenuButtonContent({
|
||||||
|
isSidebarOpen,
|
||||||
|
t,
|
||||||
|
}: {
|
||||||
|
isSidebarOpen: boolean;
|
||||||
|
t: ReturnType<typeof useI18n>["t"];
|
||||||
|
}) {
|
||||||
|
return isSidebarOpen ? (
|
||||||
|
<div className="text-muted-foreground flex w-full items-center gap-2 text-left text-sm">
|
||||||
|
<SettingsIcon className="size-4" />
|
||||||
|
<span>{t.workspace.settingsAndMore}</span>
|
||||||
|
<ChevronsUpDown className="text-muted-foreground ml-auto size-4" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex size-full items-center justify-center">
|
||||||
|
<SettingsIcon className="text-muted-foreground size-4" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function WorkspaceNavMenu() {
|
export function WorkspaceNavMenu() {
|
||||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||||
const [settingsDefaultSection, setSettingsDefaultSection] = useState<
|
const [settingsDefaultSection, setSettingsDefaultSection] = useState<
|
||||||
"appearance" | "memory" | "tools" | "skills" | "notification" | "about"
|
"appearance" | "memory" | "tools" | "skills" | "notification" | "about"
|
||||||
>("appearance");
|
>("appearance");
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
const { open: isSidebarOpen } = useSidebar();
|
const { open: isSidebarOpen } = useSidebar();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SettingsDialog
|
<SettingsDialog
|
||||||
@@ -46,91 +72,87 @@ export function WorkspaceNavMenu() {
|
|||||||
/>
|
/>
|
||||||
<SidebarMenu className="w-full">
|
<SidebarMenu className="w-full">
|
||||||
<SidebarMenuItem>
|
<SidebarMenuItem>
|
||||||
<DropdownMenu>
|
{mounted ? (
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenu>
|
||||||
<SidebarMenuButton
|
<DropdownMenuTrigger asChild>
|
||||||
size="lg"
|
<SidebarMenuButton
|
||||||
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
size="lg"
|
||||||
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
||||||
|
>
|
||||||
|
<NavMenuButtonContent isSidebarOpen={isSidebarOpen} t={t} />
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent
|
||||||
|
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
||||||
|
align="end"
|
||||||
|
sideOffset={4}
|
||||||
>
|
>
|
||||||
{isSidebarOpen ? (
|
<DropdownMenuGroup>
|
||||||
<div className="text-muted-foreground flex w-full items-center gap-2 text-left text-sm">
|
<DropdownMenuItem
|
||||||
<SettingsIcon className="size-4" />
|
onClick={() => {
|
||||||
<span>{t.workspace.settingsAndMore}</span>
|
setSettingsDefaultSection("appearance");
|
||||||
<ChevronsUpDown className="text-muted-foreground ml-auto size-4" />
|
setSettingsOpen(true);
|
||||||
</div>
|
}}
|
||||||
) : (
|
>
|
||||||
<div className="flex size-full items-center justify-center">
|
<Settings2Icon />
|
||||||
<SettingsIcon className="text-muted-foreground size-4" />
|
{t.common.settings}
|
||||||
</div>
|
</DropdownMenuItem>
|
||||||
)}
|
<DropdownMenuSeparator />
|
||||||
</SidebarMenuButton>
|
<a
|
||||||
</DropdownMenuTrigger>
|
href="https://deerflow.tech/"
|
||||||
<DropdownMenuContent
|
target="_blank"
|
||||||
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
rel="noopener noreferrer"
|
||||||
align="end"
|
>
|
||||||
sideOffset={4}
|
<DropdownMenuItem>
|
||||||
>
|
<GlobeIcon />
|
||||||
<DropdownMenuGroup>
|
{t.workspace.officialWebsite}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href="https://github.com/bytedance/deer-flow"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
<GithubIcon />
|
||||||
|
{t.workspace.visitGithub}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</a>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<a
|
||||||
|
href="https://github.com/bytedance/deer-flow/issues"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
<BugIcon />
|
||||||
|
{t.workspace.reportIssue}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</a>
|
||||||
|
<a href="mailto:support@deerflow.tech">
|
||||||
|
<DropdownMenuItem>
|
||||||
|
<MailIcon />
|
||||||
|
{t.workspace.contactUs}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</a>
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSettingsDefaultSection("appearance");
|
setSettingsDefaultSection("about");
|
||||||
setSettingsOpen(true);
|
setSettingsOpen(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Settings2Icon />
|
<InfoIcon />
|
||||||
{t.common.settings}
|
{t.workspace.about}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuSeparator />
|
</DropdownMenuContent>
|
||||||
<a
|
</DropdownMenu>
|
||||||
href="https://deerflow.tech/"
|
) : (
|
||||||
target="_blank"
|
<SidebarMenuButton size="lg" className="pointer-events-none">
|
||||||
rel="noopener noreferrer"
|
<NavMenuButtonContent isSidebarOpen={isSidebarOpen} t={t} />
|
||||||
>
|
</SidebarMenuButton>
|
||||||
<DropdownMenuItem>
|
)}
|
||||||
<GlobeIcon />
|
|
||||||
{t.workspace.officialWebsite}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
href="https://github.com/bytedance/deer-flow"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<DropdownMenuItem>
|
|
||||||
<GithubIcon />
|
|
||||||
{t.workspace.visitGithub}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</a>
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
<a
|
|
||||||
href="https://github.com/bytedance/deer-flow/issues"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<DropdownMenuItem>
|
|
||||||
<BugIcon />
|
|
||||||
{t.workspace.reportIssue}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</a>
|
|
||||||
<a href="mailto:support@deerflow.tech">
|
|
||||||
<DropdownMenuItem>
|
|
||||||
<MailIcon />
|
|
||||||
{t.workspace.contactUs}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</a>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => {
|
|
||||||
setSettingsDefaultSection("about");
|
|
||||||
setSettingsOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<InfoIcon />
|
|
||||||
{t.workspace.about}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user