Skip to content

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

Go

fix(frontend): apply code review fixes across store and UI

Naiyuan Qing4a7a9800f228
diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx
index 6fa0e8a58a..716a2e724f 100644
--- a/apps/web/app/layout.tsx
+++ b/apps/web/app/layout.tsx
@@ -2,11 +2,6 @@ import type { Metadata } from "next";
import { Geist, Geist_Mono, Inter, Playfair_Display } from "next/font/google";
import { setConfig } from "@multica/fetch";
import "@multica/ui/globals.css";
-
-setConfig({
- consoleUrl: process.env.NEXT_PUBLIC_CONSOLE_URL ?? "http://localhost:4000",
- gatewayUrl: process.env.NEXT_PUBLIC_GATEWAY_URL ?? "http://localhost:3000",
-});
import {
SidebarProvider,
SidebarInset,
@@ -16,6 +11,11 @@ import { ThemeProvider } from "@multica/ui/components/theme-provider";
import { Toaster } from "@multica/ui/components/ui/sonner";
import { HubSidebar } from "@multica/ui/components/hub-sidebar";
+setConfig({
+ consoleUrl: process.env.NEXT_PUBLIC_CONSOLE_URL ?? "http://localhost:4000",
+ gatewayUrl: process.env.NEXT_PUBLIC_GATEWAY_URL ?? "http://localhost:3000",
+});
+
const inter = Inter({ subsets: ["latin"], variable: "--font-sans" });
const geistSans = Geist({
diff --git a/packages/store/package.json b/packages/store/package.json
index 1d0fb5c3bc..e79cdef16c 100644
--- a/packages/store/package.json
+++ b/packages/store/package.json
@@ -11,6 +11,7 @@
"@multica/fetch": "workspace:*",
"@multica/sdk": "workspace:*",
"react": "catalog:",
+ "sonner": "^2.0.7",
"uuid": "^13.0.0",
"zustand": "catalog:"
},
diff --git a/packages/store/src/hub-init.ts b/packages/store/src/hub-init.ts
index 23cba21b7b..bf06c56af4 100644
--- a/packages/store/src/hub-init.ts
+++ b/packages/store/src/hub-init.ts
@@ -24,6 +24,7 @@ export function useHubInit() {
useEffect(() => {
if (status === "connected" && deviceId) {
useGatewayStore.getState().connect(deviceId)
+ return () => { useGatewayStore.getState().disconnect() }
}
}, [status, deviceId])
}
diff --git a/packages/store/src/hub.ts b/packages/store/src/hub.ts
index db50162898..ed5cc41fab 100644
--- a/packages/store/src/hub.ts
+++ b/packages/store/src/hub.ts
@@ -1,5 +1,6 @@
import { create } from "zustand"
import { consoleApi } from "@multica/fetch"
+import { toast } from "sonner"
export interface HubInfo {
hubId: string
@@ -57,7 +58,10 @@ export const useHubStore = create<HubStore>()((set, get) => ({
try {
const data = await consoleApi.get<Agent[]>("/api/agents")
set({ agents: data })
- } catch { /* silent */ }
+ } catch (e) {
+ toast.error("Failed to fetch agents")
+ console.error(e)
+ }
},
createAgent: async (options?) => {
@@ -65,7 +69,10 @@ export const useHubStore = create<HubStore>()((set, get) => ({
const data = await consoleApi.post<{ id: string }>("/api/agents", options)
await get().fetchAgents()
if (data.id) set({ activeAgentId: data.id })
- } catch { /* silent */ }
+ } catch (e) {
+ toast.error("Failed to create agent")
+ console.error(e)
+ }
},
deleteAgent: async (id) => {
@@ -73,6 +80,9 @@ export const useHubStore = create<HubStore>()((set, get) => ({
try {
await consoleApi.delete("/api/agents/" + id)
await get().fetchAgents()
- } catch { /* silent */ }
+ } catch (e) {
+ toast.error("Failed to delete agent")
+ console.error(e)
+ }
},
}))
diff --git a/packages/store/src/messages.ts b/packages/store/src/messages.ts
index 1c9d7bbb89..f2df5f2ee4 100644
--- a/packages/store/src/messages.ts
+++ b/packages/store/src/messages.ts
@@ -17,7 +17,6 @@ interface MessagesActions {
addAssistantMessage: (content: string, agentId: string) => void
updateMessage: (id: string, content: string) => void
loadMessages: (agentId: string, msgs: Message[]) => void
- getMessagesByAgent: (agentId: string) => Message[]
clearMessages: (agentId?: string) => void
}
@@ -50,10 +49,6 @@ export const useMessagesStore = create<MessagesStore>()((set, get) => ({
}))
},
- getMessagesByAgent: (agentId) => {
- return get().messages.filter((m) => m.agentId === agentId)
- },
-
clearMessages: (agentId?) => {
set((s) => ({
messages: agentId ? s.messages.filter((m) => m.agentId !== agentId) : [],
diff --git a/packages/ui/src/components/chat.tsx b/packages/ui/src/components/chat.tsx
index 07048dcfd9..a510ca3020 100644
--- a/packages/ui/src/components/chat.tsx
+++ b/packages/ui/src/components/chat.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useRef, useState, useCallback } from "react";
+import { useRef, useState, useCallback, useMemo } from "react";
import { SidebarTrigger } from "@multica/ui/components/ui/sidebar";
import { Badge } from "@multica/ui/components/ui/badge";
import { Button } from "@multica/ui/components/ui/button";
@@ -11,6 +11,7 @@ import { UserIcon, Copy01Icon, CheckmarkCircle02Icon } from "@hugeicons/core-fre
import { toast } from "@multica/ui/components/ui/sonner";
import { useHubStore, useDeviceId, useMessagesStore, useGatewayStore } from "@multica/store";
import { useScrollFade } from "@multica/ui/hooks/use-scroll-fade";
+import { Skeleton } from "@multica/ui/components/ui/skeleton";
import { cn } from "@multica/ui/lib/utils";
const STATE_VARIANT: Record<string, "default" | "secondary" | "destructive" | "outline"> = {
@@ -22,21 +23,18 @@ const STATE_VARIANT: Record<string, "default" | "secondary" | "destructive" | "o
export function Chat() {
const activeAgentId = useHubStore((s) => s.activeAgentId)
- const hub = useHubStore((s) => s.hub)
- const addUserMessage = useMessagesStore((s) => s.addUserMessage)
- const messages = useMessagesStore((s) => s.messages)
const gwState = useGatewayStore((s) => s.connectionState)
- const send = useGatewayStore((s) => s.send)
- const handleSend = (text: string) => {
- if (!hub?.hubId || !activeAgentId) return
- addUserMessage(text, activeAgentId)
- send(hub.hubId, "message", { agentId: activeAgentId, content: text })
- }
+ const messages = useMessagesStore((s) => s.messages)
+ const filtered = useMemo(() => messages.filter(m => m.agentId === activeAgentId), [messages, activeAgentId])
- const filtered = activeAgentId
- ? messages.filter(m => m.agentId === activeAgentId)
- : []
+ const handleSend = useCallback((text: string) => {
+ const hub = useHubStore.getState().hub
+ const agentId = useHubStore.getState().activeAgentId
+ if (!hub?.hubId || !agentId) return
+ useMessagesStore.getState().addUserMessage(text, agentId)
+ useGatewayStore.getState().send(hub.hubId, "message", { agentId, content: text })
+ }, [])
const canSend = gwState === "registered" && !!activeAgentId
@@ -44,10 +42,14 @@ export function Chat() {
const [deviceCopied, setDeviceCopied] = useState(false)
const handleCopyDevice = useCallback(async () => {
if (!deviceId) return
- await navigator.clipboard.writeText(deviceId)
- setDeviceCopied(true)
- toast.success("Device ID copied")
- setTimeout(() => setDeviceCopied(false), 2000)
+ try {
+ await navigator.clipboard.writeText(deviceId)
+ setDeviceCopied(true)
+ toast.success("Device ID copied")
+ setTimeout(() => setDeviceCopied(false), 2000)
+ } catch {
+ toast.error("Failed to copy")
+ }
}, [deviceId])
const mainRef = useRef<HTMLElement>(null)
@@ -57,7 +59,7 @@ export function Chat() {
<div className="h-dvh flex flex-col overflow-hidden w-full">
<header className="flex items-center gap-2 p-2">
<SidebarTrigger />
- {deviceId && (
+ {deviceId ? (
<>
<span className="text-xs text-muted-foreground font-mono">
{deviceId}
@@ -75,6 +77,8 @@ export function Chat() {
/>
</Button>
</>
+ ) : (
+ <Skeleton className="h-4 w-56" />
)}
<Badge variant={STATE_VARIANT[gwState] ?? "outline"} className="text-xs">
{gwState}
diff --git a/packages/ui/src/components/hub-sidebar.tsx b/packages/ui/src/components/hub-sidebar.tsx
index dbbd4df8d6..fdd51596b8 100644
--- a/packages/ui/src/components/hub-sidebar.tsx
+++ b/packages/ui/src/components/hub-sidebar.tsx
@@ -13,6 +13,7 @@ import { HugeiconsIcon } from "@hugeicons/react"
import { PlusSignIcon, Delete02Icon } from "@hugeicons/core-free-icons"
import { useHubStore } from "@multica/store"
import { useHubInit } from "@multica/store"
+import { Skeleton } from "@multica/ui/components/ui/skeleton"
const STATUS_DOT: Record<string, string> = {
connected: "bg-green-500/60",
@@ -49,11 +50,13 @@ export function HubSidebar() {
<span className={`size-2 rounded-full shrink-0 ${STATUS_DOT[status]}`} />
<span className="text-muted-foreground/70 text-xs">{STATUS_LABEL[status]}</span>
</div>
- {status === "connected" && hub && (
+ {status === "connected" && hub ? (
<div className="px-2 text-xs text-muted-foreground/50 font-mono truncate">
{hub.hubId}
</div>
- )}
+ ) : (status === "idle" || status === "loading") ? (
+ <Skeleton className="mx-2 h-3.5 w-32" />
+ ) : null}
{status === "error" && (
<div className="px-2 pt-1">
<Button variant="outline" size="sm" onClick={fetchHub} className="w-full text-xs">
@@ -64,6 +67,19 @@ export function HubSidebar() {
</SidebarGroupContent>
</SidebarGroup>
+ {(status === "idle" || status === "loading") && (
+ <SidebarGroup>
+ <SidebarGroupLabel>Agents</SidebarGroupLabel>
+ <SidebarGroupContent>
+ <div className="space-y-2 px-2 py-1">
+ <Skeleton className="h-6 w-full rounded-md" />
+ <Skeleton className="h-6 w-3/4 rounded-md" />
+ <Skeleton className="h-6 w-5/6 rounded-md" />
+ </div>
+ </SidebarGroupContent>
+ </SidebarGroup>
+ )}
+
{status === "connected" && (
<SidebarGroup>
<SidebarGroupLabel>Agents</SidebarGroupLabel>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c5762deddd..0848589316 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -291,6 +291,9 @@ importers:
react:
specifier: 'catalog:'
version: 19.2.3
+ sonner:
+ specifier: ^2.0.7
uuid:
specifier: ^13.0.0
version: 13.0.0