diff --git a/src/renderer/src/components/layout/AppShell.tsx b/src/renderer/src/components/layout/AppShell.tsx index a7cbcf2a9d..aece19abd7 100644 --- a/src/renderer/src/components/layout/AppShell.tsx +++ b/src/renderer/src/components/layout/AppShell.tsx @@ -1,40 +1,12 @@ import { cn, Tabs, TabsList, TabsTrigger } from '@cherrystudio/ui' -import { X } from 'lucide-react' +import { Plus, X } from 'lucide-react' import { Activity } from 'react' import { v4 as uuid } from 'uuid' import { useTabs } from '../../hooks/useTabs' +import Sidebar from '../app/Sidebar' import { TabRouter } from './TabRouter' -// Mock Sidebar component (TODO: Replace with actual Sidebar) -const Sidebar = ({ onNavigate }: { onNavigate: (path: string, title: string) => void }) => { - const menuItems = [ - { path: '/', title: 'Home', icon: 'H' }, - { path: '/settings', title: 'Settings', icon: 'S' } - ] - - return ( - - ) -} - // Mock Webview component (TODO: Replace with actual MinApp/Webview) const WebviewContainer = ({ url, isActive }: { url: string; isActive: boolean }) => ( @@ -46,33 +18,27 @@ const WebviewContainer = ({ url, isActive }: { url: string; isActive: boolean }) ) export const AppShell = () => { - const { tabs, activeTabId, setActiveTab, closeTab, addTab, updateTab } = useTabs() - - // Sidebar navigation: find existing tab or create new one - const handleSidebarNavigate = (path: string, title: string) => { - const existingTab = tabs.find((t) => t.type === 'route' && t.url === path) - - if (existingTab) { - setActiveTab(existingTab.id) - } else { - addTab({ - id: uuid(), - type: 'route', - url: path, - title - }) - } - } + const { tabs, activeTabId, setActiveTab, closeTab, updateTab, addTab } = useTabs() // Sync internal navigation back to tab state const handleUrlChange = (tabId: string, url: string) => { updateTab(tabId, { url }) } + // 新增 Tab(默认打开首页) + const handleAddTab = () => { + addTab({ + id: uuid(), + type: 'route', + url: '/', + title: 'New Tab', + }) + } + return (
{/* Zone 1: Sidebar */} - +
{/* Zone 2: Tab Bar */} @@ -101,6 +67,14 @@ export const AppShell = () => { )} ))} + {/* 新增 Tab 按钮 - 跟随最后一个 Tab */} + diff --git a/src/renderer/src/components/layout/TabRouter.tsx b/src/renderer/src/components/layout/TabRouter.tsx index cebeeff605..3de4ded8f8 100644 --- a/src/renderer/src/components/layout/TabRouter.tsx +++ b/src/renderer/src/components/layout/TabRouter.tsx @@ -34,6 +34,14 @@ export const TabRouter = ({ tab, isActive, onUrlChange }: TabRouterProps) => { }) }, [router, tab.url, onUrlChange]) + // Navigate when tab.url changes externally (e.g., from Sidebar) + useEffect(() => { + const currentPath = router.state.location.pathname + if (tab.url !== currentPath) { + router.navigate({ to: tab.url }) + } + }, [router, tab.url]) + return (