mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-12 10:16:37 +08:00
migrate frontend
This commit is contained in:
@@ -4,7 +4,7 @@ import {useState} from 'react';
|
||||
import {useQuery} from '@tanstack/react-query';
|
||||
import {usePathname} from 'next/navigation';
|
||||
|
||||
import {VersionUpgradeDialog} from '@/app/(main)/openflare/components/version-upgrade-dialog';
|
||||
import {VersionUpgradeDialog} from '@/app/(main)/components/version-upgrade-dialog';
|
||||
import {Badge} from '@/components/ui/badge';
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {useUser} from '@/contexts/user-context';
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
openflareLatestReleaseQueryKey,
|
||||
openflarePublicStatusQueryKey,
|
||||
} from '@/lib/hooks/use-openflare-server-upgrade';
|
||||
import {isOpenFlareConsoleRoute} from '@/lib/navigation/openflare-nav';
|
||||
import {StatusService, UpdateService} from '@/lib/services/openflare';
|
||||
|
||||
export function OpenFlareVersionEntry() {
|
||||
@@ -19,7 +20,7 @@ export function OpenFlareVersionEntry() {
|
||||
const {user} = useUser();
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
|
||||
const isOpenFlareRoute = pathname.startsWith('/openflare');
|
||||
const isOpenFlareRoute = isOpenFlareConsoleRoute(pathname);
|
||||
const canUpgrade = Boolean(user?.is_admin);
|
||||
|
||||
const statusQuery = useQuery({
|
||||
|
||||
@@ -53,7 +53,6 @@ import {
|
||||
FileQuestionMark,
|
||||
FileText,
|
||||
FolderOpen,
|
||||
Home,
|
||||
Layers,
|
||||
LogOut,
|
||||
Settings,
|
||||
@@ -68,10 +67,6 @@ import {openflareNavItems} from "@/lib/navigation/openflare-nav"
|
||||
|
||||
/* 导航数据 */
|
||||
const data = {
|
||||
navMain: [
|
||||
{ title: "首页", url: "/home", icon: Home },
|
||||
{ title: "我的文件", url: "/files", icon: FolderOpen },
|
||||
],
|
||||
admin: [
|
||||
{ title: "用户管理", url: "/admin/users", icon: UserRound },
|
||||
{ title: "任务管理", url: "/admin/tasks", icon: Layers },
|
||||
@@ -166,11 +161,6 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||
}
|
||||
}
|
||||
|
||||
const navMainFiltered = React.useMemo(() => {
|
||||
const displayConfig = parseMenuDisplayConfig(config?.menu_display_config)
|
||||
return data.navMain.filter((item) => displayConfig[item.url] !== false)
|
||||
}, [config])
|
||||
|
||||
const adminFiltered = React.useMemo(() => {
|
||||
const displayConfig = parseMenuDisplayConfig(config?.menu_display_config)
|
||||
return data.admin.filter((item) => displayConfig[item.url] !== false)
|
||||
@@ -304,34 +294,8 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||
</DropdownMenu>
|
||||
</SidebarHeader>
|
||||
<SidebarContent className="group-data-[collapsible=icon]">
|
||||
{navMainFiltered.length > 0 && (
|
||||
<SidebarGroup className="py-0">
|
||||
<SidebarGroupContent className="py-1">
|
||||
<SidebarMenu className="gap-1">
|
||||
{navMainFiltered.map((item) => (
|
||||
<SidebarMenuItem key={item.title}>
|
||||
<SidebarMenuButton
|
||||
tooltip={item.title}
|
||||
isActive={pathname === item.url}
|
||||
asChild
|
||||
>
|
||||
<Link href={item.url} onClick={handleCloseSidebar}>
|
||||
{item.icon && <item.icon />}
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
)}
|
||||
|
||||
{openflareNavItems.length > 0 && (
|
||||
<SidebarGroup className="py-0 pt-4">
|
||||
<SidebarGroupLabel className="text-xs font-normal text-muted-foreground">
|
||||
OpenFlare
|
||||
</SidebarGroupLabel>
|
||||
<SidebarGroup className="py-0">
|
||||
<SidebarGroupContent className="py-1">
|
||||
<SidebarMenu className="gap-1">
|
||||
{openflareNavItems.map((item) => (
|
||||
@@ -339,8 +303,8 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||
<SidebarMenuButton
|
||||
tooltip={item.title}
|
||||
isActive={
|
||||
item.url === "/openflare"
|
||||
? pathname === "/openflare"
|
||||
item.url === "/"
|
||||
? pathname === "/"
|
||||
: pathname === item.url || pathname.startsWith(`${item.url}/`)
|
||||
}
|
||||
asChild
|
||||
|
||||
Reference in New Issue
Block a user