Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

refactor(desktop): update shell, tab-bar, and login for tab-based architecture

Naiyuan Qing1f9ce6582c45
diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsx
index 9324abad65..b1617efd5f 100644
--- a/apps/desktop/src/renderer/src/App.tsx
+++ b/apps/desktop/src/renderer/src/App.tsx
@@ -1,8 +1,26 @@
-import { RouterProvider } from "react-router-dom";
import { CoreProvider } from "@multica/core/platform";
+import { useAuthStore } from "@multica/core/auth";
import { ThemeProvider } from "@multica/ui/components/common/theme-provider";
+import { MulticaIcon } from "@multica/ui/components/common/multica-icon";
import { Toaster } from "sonner";
-import { router } from "./router";
+import { DesktopLoginPage } from "./pages/login";
+import { DesktopShell } from "./components/desktop-layout";
+
+function AppContent() {
+ const user = useAuthStore((s) => s.user);
+ const isLoading = useAuthStore((s) => s.isLoading);
+
+ if (isLoading) {
+ return (
+ <div className="flex h-screen items-center justify-center">
+ <MulticaIcon className="size-6 animate-pulse" />
+ </div>
+ );
+ }
+
+ if (!user) return <DesktopLoginPage />;
+ return <DesktopShell />;
+}
export default function App() {
return (
@@ -11,7 +29,7 @@ export default function App() {
apiBaseUrl={import.meta.env.VITE_API_URL || "http://localhost:8080"}
wsUrl={import.meta.env.VITE_WS_URL || "ws://localhost:8080/ws"}
>
- <RouterProvider router={router} />
+ <AppContent />
</CoreProvider>
<Toaster />
</ThemeProvider>
diff --git a/apps/desktop/src/renderer/src/components/desktop-layout.tsx b/apps/desktop/src/renderer/src/components/desktop-layout.tsx
index 8df94eb95b..09bc65e119 100644
--- a/apps/desktop/src/renderer/src/components/desktop-layout.tsx
+++ b/apps/desktop/src/renderer/src/components/desktop-layout.tsx
@@ -1,8 +1,7 @@
import { useEffect } from "react";
-import { Outlet, useNavigate } from "react-router-dom";
import { ChevronLeft, ChevronRight } from "lucide-react";
-import { useNavigationHistory } from "@/hooks/use-history-stack";
-import { useTabSync } from "@/hooks/use-tab-sync";
+import { useTabHistory } from "@/hooks/use-tab-history";
+import { useActiveTitleSync } from "@/hooks/use-tab-sync";
import { useTabStore, resolveRouteIcon } from "@/stores/tab-store";
import { SidebarProvider } from "@multica/ui/components/ui/sidebar";
import { ModalRegistry } from "@multica/views/modals/registry";
@@ -11,9 +10,10 @@ import { SearchCommand, SearchTrigger } from "@multica/views/search";
import { DesktopNavigationProvider } from "@/platform/navigation";
import { MulticaIcon } from "@multica/ui/components/common/multica-icon";
import { TabBar } from "./tab-bar";
+import { TabContent } from "./tab-content";
function SidebarTopBar() {
- const { canGoBack, canGoForward, goBack, goForward } = useNavigationHistory();
+ const { canGoBack, canGoForward, goBack, goForward } = useTabHistory();
return (
<div
@@ -43,17 +43,7 @@ function SidebarTopBar() {
);
}
-export function DesktopLayout() {
- return (
- <DesktopNavigationProvider>
- <DesktopLayoutInner />
- </DesktopNavigationProvider>
- );
-}
-
function useInternalLinkHandler() {
- const navigate = useNavigate();
-
useEffect(() => {
const handler = (e: Event) => {
const path = (e as CustomEvent).detail?.path;
@@ -62,47 +52,48 @@ function useInternalLinkHandler() {
const store = useTabStore.getState();
const tabId = store.openTab(path, path, icon);
store.setActiveTab(tabId);
- navigate(path);
};
window.addEventListener("multica:navigate", handler);
return () => window.removeEventListener("multica:navigate", handler);
- }, [navigate]);
+ }, []);
}
-function DesktopLayoutInner() {
- useTabSync();
+export function DesktopShell() {
useInternalLinkHandler();
+ useActiveTitleSync();
return (
- <DashboardGuard
- loginPath="/login"
- loadingFallback={
- <div className="flex h-screen items-center justify-center">
- <MulticaIcon className="size-6 animate-pulse" />
- </div>
- }
- >
- <div className="flex h-screen">
- <SidebarProvider className="flex-1">
- <AppSidebar topSlot={<SidebarTopBar />} searchSlot={<SearchTrigger />} />
- {/* Right side: header + content container */}
- <div className="flex flex-1 min-w-0 flex-col">
- {/* Tab bar + drag region */}
- <header
- className="h-12 shrink-0"
- style={{ WebkitAppRegion: "drag" } as React.CSSProperties}
- >
- <TabBar />
- </header>
- {/* Content area with inset styling */}
- <div className="flex flex-1 min-h-0 flex-col overflow-hidden mr-2 mb-2 ml-0.5 rounded-xl shadow-sm bg-background">
- <Outlet />
- <ModalRegistry />
- <SearchCommand />
- </div>
+ <DesktopNavigationProvider>
+ <DashboardGuard
+ loginPath="/login"
+ loadingFallback={
+ <div className="flex h-screen items-center justify-center">
+ <MulticaIcon className="size-6 animate-pulse" />
</div>
- </SidebarProvider>
- </div>
- </DashboardGuard>
+ }
+ >
+ <div className="flex h-screen">
+ <SidebarProvider className="flex-1">
+ <AppSidebar topSlot={<SidebarTopBar />} searchSlot={<SearchTrigger />} />
+ {/* Right side: header + content container */}
+ <div className="flex flex-1 min-w-0 flex-col">
+ {/* Tab bar + drag region */}
+ <header
+ className="h-12 shrink-0"
+ style={{ WebkitAppRegion: "drag" } as React.CSSProperties}
+ >
+ <TabBar />
+ </header>
+ {/* Content area with inset styling */}
+ <div className="flex flex-1 min-h-0 flex-col overflow-hidden mr-2 mb-2 ml-0.5 rounded-xl shadow-sm bg-background">
+ <TabContent />
+ </div>
+ </div>
+ </SidebarProvider>
+ </div>
+ <ModalRegistry />
+ <SearchCommand />
+ </DashboardGuard>
+ </DesktopNavigationProvider>
);
}
diff --git a/apps/desktop/src/renderer/src/components/tab-bar.tsx b/apps/desktop/src/renderer/src/components/tab-bar.tsx
index 4f994d191c..eaf4004e26 100644
--- a/apps/desktop/src/renderer/src/components/tab-bar.tsx
+++ b/apps/desktop/src/renderer/src/components/tab-bar.tsx
@@ -1,4 +1,3 @@
-import { useNavigate } from "react-router-dom";
import {
Inbox,
CircleUser,
@@ -25,7 +24,6 @@ const TAB_ICONS: Record<string, LucideIcon> = {
};
function TabItem({ tab, isActive }: { tab: Tab; isActive: boolean }) {
- const navigate = useNavigate();
const setActiveTab = useTabStore((s) => s.setActiveTab);
const closeTab = useTabStore((s) => s.closeTab);
@@ -34,13 +32,13 @@ function TabItem({ tab, isActive }: { tab: Tab; isActive: boolean }) {
const handleClick = () => {
if (isActive) return;
setActiveTab(tab.id);
- navigate(tab.path);
+ // No navigate() — Activity handles visibility
};
const handleClose = (e: React.MouseEvent) => {
e.stopPropagation();
- const newPath = closeTab(tab.id);
- if (newPath) navigate(newPath);
+ closeTab(tab.id);
+ // No navigate() — store handles activeTabId switch
};
return (
@@ -50,8 +48,8 @@ function TabItem({ tab, isActive }: { tab: Tab; isActive: boolean }) {
"group flex h-7 w-40 items-center gap-1.5 rounded-md px-2 text-xs transition-colors",
"select-none cursor-default",
isActive
- ? "bg-sidebar-accent text-sidebar-accent-foreground"
- : "bg-sidebar-accent/60 text-muted-foreground hover:bg-sidebar-accent/80",
+ ? "bg-sidebar-accent font-medium text-sidebar-accent-foreground"
+ : "bg-sidebar-accent/50 text-muted-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
)}
>
{Icon && <Icon className="size-3.5 shrink-0" />}
@@ -75,7 +73,6 @@ function TabItem({ tab, isActive }: { tab: Tab; isActive: boolean }) {
}
function NewTabButton() {
- const navigate = useNavigate();
const addTab = useTabStore((s) => s.addTab);
const setActiveTab = useTabStore((s) => s.setActiveTab);
@@ -83,7 +80,7 @@ function NewTabButton() {
const path = "/issues";
const tabId = addTab(path, "Issues", resolveRouteIcon(path));
setActiveTab(tabId);
- navigate(path);
+ // No navigate() — new tab's router starts at /issues automatically
};
return (
diff --git a/apps/desktop/src/renderer/src/hooks/use-tab-sync.ts b/apps/desktop/src/renderer/src/hooks/use-tab-sync.ts
index 182b1ab09f..39785b7e8d 100644
--- a/apps/desktop/src/renderer/src/hooks/use-tab-sync.ts
+++ b/apps/desktop/src/renderer/src/hooks/use-tab-sync.ts
@@ -1,45 +1,13 @@
-import { useEffect, useRef } from "react";
-import { useLocation } from "react-router-dom";
-import { useTabStore, resolveRouteIcon } from "@/stores/tab-store";
+import { useEffect } from "react";
+import { useTabStore } from "@/stores/tab-store";
/**
- * Keeps the active tab in sync with the current URL and document.title.
+ * Watches document.title via MutationObserver and updates the active tab's title.
*
- * Two sync directions:
- * 1. URL change → update active tab's path (and set a default title from the route)
- * 2. document.title change → update active tab's title (pages set this naturally)
- *
- * Tab switches (clicking another tab) are ignored — the tab already has its metadata.
+ * Pages set document.title via TitleSync (route handle.title) or useDocumentTitle().
+ * This observer picks up the change and syncs it to the tab store.
*/
-export function useTabSync() {
- const location = useLocation();
- const isTabSwitch = useRef(false);
-
- // Detect tab switches so we don't overwrite metadata
- useEffect(() => {
- return useTabStore.subscribe((state, prev) => {
- if (state.activeTabId !== prev.activeTabId) {
- isTabSwitch.current = true;
- }
- });
- }, []);
-
- // Sync URL → tab path
- useEffect(() => {
- if (isTabSwitch.current) {
- isTabSwitch.current = false;
- return;
- }
-
- const { tabs, activeTabId } = useTabStore.getState();
- const activeTab = tabs.find((t) => t.id === activeTabId);
- if (activeTab && activeTab.path !== location.pathname) {
- const icon = resolveRouteIcon(location.pathname);
- useTabStore.getState().updateActiveTab(location.pathname, document.title, icon);
- }
- }, [location.pathname]);
-
- // Sync document.title → tab title
+export function useActiveTitleSync() {
useEffect(() => {
const observer = new MutationObserver(() => {
const title = document.title;
@@ -47,7 +15,7 @@ export function useTabSync() {
const { tabs, activeTabId } = useTabStore.getState();
const activeTab = tabs.find((t) => t.id === activeTabId);
if (activeTab && activeTab.title !== title) {
- useTabStore.getState().updateActiveTab(activeTab.path, title, activeTab.icon);
+ useTabStore.getState().updateTab(activeTabId, { title });
}
});
diff --git a/apps/desktop/src/renderer/src/pages/login.tsx b/apps/desktop/src/renderer/src/pages/login.tsx
index 057db87de6..8877634901 100644
--- a/apps/desktop/src/renderer/src/pages/login.tsx
+++ b/apps/desktop/src/renderer/src/pages/login.tsx
@@ -1,10 +1,7 @@
-import { useNavigate } from "react-router-dom";
import { LoginPage } from "@multica/views/auth";
import { MulticaIcon } from "@multica/ui/components/common/multica-icon";
export function DesktopLoginPage() {
- const navigate = useNavigate();
-
return (
<div className="flex h-screen flex-col">
{/* Traffic light inset */}
@@ -14,7 +11,9 @@ export function DesktopLoginPage() {
/>
<LoginPage
logo={<MulticaIcon bordered size="lg" />}
- onSuccess={() => navigate("/issues", { replace: true })}
+ onSuccess={() => {
+ // Auth store update triggers AppContent re-render → shows DesktopShell
+ }}
/>
</div>
);