Spaces:
Running
Running
Download src/components/layout/TopBar.tsx from evalstate/mcp-webcam: direct link, hf CLI and curl.
- Browser
- Download file 7.61 kB
-
https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/layout/TopBar.tsx
- Command line
-
hf download hf://spaces/evalstate/mcp-webcam/src/components/layout/TopBar.tsx
-
curl -L -o TopBar.tsx https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/layout/TopBar.tsx
7.61 kB
| import { useState } from 'react'; | |
| import { | |
| ChevronDown, | |
| ChevronUp, | |
| ExternalLink, | |
| Plug, | |
| Radio, | |
| User as UserIcon, | |
| Check, | |
| X, | |
| } from 'lucide-react'; | |
| import type { AppConfigView, DashboardState } from '../../../shared/api-types'; | |
| import { Badge } from '@/components/ui/badge'; | |
| import { Button } from '@/components/ui/button'; | |
| import { Input } from '@/components/ui/input'; | |
| import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; | |
| import { ThemeToggle } from './ThemeToggle'; | |
| import type { Theme } from '@/lib/theme'; | |
| import { cn } from '@/lib/utils'; | |
| export function TopBar({ | |
| config, | |
| state, | |
| user, | |
| onChangeUser, | |
| connected, | |
| mockMode, | |
| connectOpen, | |
| onToggleConnect, | |
| theme, | |
| onToggleTheme, | |
| }: { | |
| config: AppConfigView; | |
| state: DashboardState | null; | |
| user: string; | |
| onChangeUser: (nextUser: string) => void; | |
| connected: boolean; | |
| mockMode: boolean; | |
| connectOpen: boolean; | |
| onToggleConnect: () => void; | |
| theme: Theme; | |
| onToggleTheme: () => void; | |
| }) { | |
| const [editingUser, setEditingUser] = useState(false); | |
| const [draftUser, setDraftUser] = useState(user); | |
| const pushCount = state?.push.length ?? 0; | |
| const pollCount = state?.pollers.filter((p) => p.status !== 'gone').length ?? 0; | |
| const callerCount = state?.callers.length ?? 0; | |
| const showUserSwitcher = config.mcpHostConfigured || user !== 'default'; | |
| const commitUser = () => { | |
| const trimmed = draftUser.trim(); | |
| if (trimmed) onChangeUser(trimmed); | |
| setEditingUser(false); | |
| }; | |
| return ( | |
| <header className="sticky top-0 z-30 border-b border-line bg-bg/90 backdrop-blur-md"> | |
| <div className="mx-auto flex max-w-[1440px] flex-wrap items-center justify-between gap-2 px-4 py-2.5"> | |
| {/* Left: brand + version + mode + user */} | |
| <div className="flex flex-wrap items-center gap-2"> | |
| <div className="flex items-center gap-2"> | |
| <span className="relative flex h-6 w-6 items-center justify-center rounded-lg border border-line-strong bg-panel"> | |
| <Radio className="h-3.5 w-3.5 text-push" /> | |
| <span | |
| className={cn( | |
| 'absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full ring-2 ring-bg', | |
| mockMode ? 'bg-event' : connected ? 'bg-push' : 'bg-danger animate-pulse', | |
| )} | |
| /> | |
| </span> | |
| <span className="text-sm font-semibold tracking-tight text-fg">mcp-webcam</span> | |
| <Badge variant="muted" className="font-mono text-[10px]"> | |
| v{config.version} | |
| </Badge> | |
| </div> | |
| <Badge variant={config.mode === 'http' ? 'push' : 'call'} className="font-mono text-[10px]"> | |
| {config.mode === 'http' | |
| ? `HTTP 路 ${config.modernProtocol}${config.legacyFallback ? ' + 2025' : ''}` | |
| : 'STDIO'} | |
| </Badge> | |
| {mockMode && ( | |
| <Badge variant="event" className="font-mono text-[10px]"> | |
| MOCK MODE | |
| </Badge> | |
| )} | |
| {showUserSwitcher && ( | |
| <div className="flex items-center"> | |
| {editingUser ? ( | |
| <form | |
| className="flex items-center gap-1" | |
| onSubmit={(e) => { | |
| e.preventDefault(); | |
| commitUser(); | |
| }} | |
| > | |
| <Input | |
| value={draftUser} | |
| onChange={(e) => setDraftUser(e.target.value)} | |
| className="h-6.5 w-32 font-mono text-[11px]" | |
| placeholder="room-id" | |
| autoFocus | |
| onKeyDown={(e) => { | |
| if (e.key === 'Escape') { | |
| setDraftUser(user); | |
| setEditingUser(false); | |
| } | |
| }} | |
| /> | |
| <Button type="submit" variant="ghost" size="icon-sm" className="h-6.5 w-6.5" aria-label="Apply user"> | |
| <Check className="h-3 w-3 text-push" /> | |
| </Button> | |
| <Button | |
| type="button" | |
| variant="ghost" | |
| size="icon-sm" | |
| className="h-6.5 w-6.5" | |
| aria-label="Cancel" | |
| onClick={() => { | |
| setDraftUser(user); | |
| setEditingUser(false); | |
| }} | |
| > | |
| <X className="h-3 w-3" /> | |
| </Button> | |
| </form> | |
| ) : ( | |
| <Tooltip> | |
| <TooltipTrigger asChild> | |
| <button | |
| type="button" | |
| onClick={() => { | |
| setDraftUser(user); | |
| setEditingUser(true); | |
| }} | |
| className="inline-flex items-center gap-1 rounded-md border border-line bg-panel px-2 py-1 font-mono text-[11px] text-fg transition-colors hover:border-line-strong cursor-pointer" | |
| > | |
| <UserIcon className="h-3 w-3 text-muted" /> | |
| <span>{user}</span> | |
| </button> | |
| </TooltipTrigger> | |
| <TooltipContent>Click to switch user / room (?user=)</TooltipContent> | |
| </Tooltip> | |
| )} | |
| </div> | |
| )} | |
| </div> | |
| {/* Right: live counters + connect + theme + github */} | |
| <div className="flex items-center gap-2"> | |
| <div className="hidden items-center gap-2 rounded-lg border border-line bg-panel px-2.5 py-1 text-[11px] tabular-nums md:flex"> | |
| <span className="flex items-center gap-1.5 text-muted"> | |
| <span className="h-1.5 w-1.5 rounded-full bg-push" /> | |
| <strong className="font-medium text-fg">{pushCount}</strong> push | |
| </span> | |
| <span className="text-line-strong">路</span> | |
| <span className="flex items-center gap-1.5 text-muted"> | |
| <span className="h-1.5 w-1.5 rounded-full bg-poll" /> | |
| <strong className="font-medium text-fg">{pollCount}</strong> poll | |
| </span> | |
| <span className="text-line-strong">路</span> | |
| <span className="flex items-center gap-1.5 text-muted"> | |
| <span className="h-1.5 w-1.5 rounded-full bg-call" /> | |
| <strong className="font-medium text-fg">{callerCount}</strong> callers | |
| </span> | |
| </div> | |
| <Button | |
| variant={connectOpen ? 'default' : 'secondary'} | |
| size="sm" | |
| onClick={onToggleConnect} | |
| className="gap-1.5" | |
| > | |
| <Plug className="h-3.5 w-3.5" /> | |
| <span>Connect</span> | |
| {connectOpen ? <ChevronUp className="h-3 w-3" /> : <ChevronDown className="h-3 w-3" />} | |
| </Button> | |
| <ThemeToggle theme={theme} onToggle={onToggleTheme} /> | |
| <Tooltip> | |
| <TooltipTrigger asChild> | |
| <Button variant="ghost" size="icon-sm" asChild> | |
| <a | |
| href="https://github.com/evalstate/mcp-webcam" | |
| target="_blank" | |
| rel="noreferrer" | |
| aria-label="GitHub repository" | |
| > | |
| <ExternalLink className="h-3.5 w-3.5" /> | |
| </a> | |
| </Button> | |
| </TooltipTrigger> | |
| <TooltipContent>GitHub 路 evalstate/mcp-webcam</TooltipContent> | |
| </Tooltip> | |
| </div> | |
| </div> | |
| </header> | |
| ); | |
| } | |