Replace the legacy folder + welcome routes with a unified /workspace route that hosts all folders, conversations, tabs, and terminals in one window. - Persist opened tabs to the database (opened_tabs entity + migration) so tab layout survives restarts and deep-link bootstrap restores state - Replace FolderContext shim with AppWorkspaceProvider, ActiveFolderProvider, and TabProvider; expose both opened (folders) and full DB (allFolders) listings via list_all_folder_details - Return conversations across all non-deleted folders from list_all when no folder filter is given, so the sidebar can show every folder's history - Add ConversationContextBar above the chat input with folder picker (auto-opens unopened folders on select), branch picker, and commit / push / merge / stash entries to restore BranchDropdown functionality - Rework sidebar with stats header, search, flat / folder-grouped view modes (localStorage-persisted), reveal-in-sidebar event subscriber, and per-folder context menu (focus, close tabs, remove from workspace); indent conversations under folder headers in grouped mode - Gate terminal creation on active folder and show folder context - Remove deprecated BranchDropdown, FolderNameDropdown, welcome route, and per-folder window commands - Localize all new strings across 10 locales
171 lines
5.4 KiB
TypeScript
171 lines
5.4 KiB
TypeScript
"use client"
|
|
|
|
import { useMemo, useRef, useState } from "react"
|
|
import { Minus, Plus, X } from "lucide-react"
|
|
import { useTranslations } from "next-intl"
|
|
import { useActiveFolder } from "@/contexts/active-folder-context"
|
|
import { useAppWorkspace } from "@/contexts/app-workspace-context"
|
|
import { useTerminalContext } from "@/contexts/terminal-context"
|
|
import { useShortcutSettings } from "@/hooks/use-shortcut-settings"
|
|
import { useIsMac } from "@/hooks/use-is-mac"
|
|
import { formatShortcutLabel } from "@/lib/keyboard-shortcuts"
|
|
import { Button } from "@/components/ui/button"
|
|
import {
|
|
ContextMenu,
|
|
ContextMenuContent,
|
|
ContextMenuItem,
|
|
ContextMenuSeparator,
|
|
ContextMenuTrigger,
|
|
} from "@/components/ui/context-menu"
|
|
import { FolderBadge } from "@/components/ui/folder-badge"
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip"
|
|
|
|
export function TerminalTabBar() {
|
|
const t = useTranslations("Folder.terminal")
|
|
const { shortcuts } = useShortcutSettings()
|
|
const isMac = useIsMac()
|
|
const {
|
|
tabs,
|
|
activeTabId,
|
|
switchTerminal,
|
|
closeTerminal,
|
|
closeOtherTerminals,
|
|
closeAllTerminals,
|
|
renameTerminal,
|
|
createTerminal,
|
|
toggle,
|
|
} = useTerminalContext()
|
|
const { activeFolderId } = useActiveFolder()
|
|
const { folders } = useAppWorkspace()
|
|
|
|
const folderIndex = useMemo(() => {
|
|
const map = new Map<number, string>()
|
|
for (const f of folders) map.set(f.id, f.name)
|
|
return map
|
|
}, [folders])
|
|
|
|
const canCreateTerminal = activeFolderId != null
|
|
|
|
const [editingId, setEditingId] = useState<string | null>(null)
|
|
const [editValue, setEditValue] = useState("")
|
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
|
|
const startRename = (id: string, title: string) => {
|
|
setEditingId(id)
|
|
setEditValue(title)
|
|
setTimeout(() => inputRef.current?.select(), 0)
|
|
}
|
|
|
|
const commitRename = () => {
|
|
if (editingId && editValue.trim()) {
|
|
renameTerminal(editingId, editValue.trim())
|
|
}
|
|
setEditingId(null)
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center h-8 bg-muted/50 border-b gap-0.5 px-1 shrink-0">
|
|
{tabs.map((tab) => (
|
|
<ContextMenu key={tab.id}>
|
|
<ContextMenuTrigger asChild>
|
|
<div
|
|
className={`flex items-center gap-1 h-6 px-2 rounded-sm text-xs cursor-pointer select-none ${
|
|
tab.id === activeTabId
|
|
? "bg-background text-foreground"
|
|
: "text-muted-foreground hover:text-foreground hover:bg-muted"
|
|
}`}
|
|
onClick={() => switchTerminal(tab.id)}
|
|
>
|
|
<FolderBadge
|
|
folderId={tab.folderId}
|
|
folderName={
|
|
folderIndex.get(tab.folderId) ?? String(tab.folderId)
|
|
}
|
|
size="sm"
|
|
/>
|
|
{editingId === tab.id ? (
|
|
<input
|
|
ref={inputRef}
|
|
className="bg-transparent outline-none border border-primary/50 rounded px-0.5 w-20 text-xs"
|
|
value={editValue}
|
|
onChange={(e) => setEditValue(e.target.value)}
|
|
onBlur={commitRename}
|
|
onKeyDown={(e) => {
|
|
if (e.key === "Enter") commitRename()
|
|
if (e.key === "Escape") setEditingId(null)
|
|
}}
|
|
/>
|
|
) : (
|
|
<span className="truncate max-w-[120px]">{tab.title}</span>
|
|
)}
|
|
<button
|
|
className="ml-1 rounded-sm hover:bg-muted-foreground/20 p-0.5"
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
closeTerminal(tab.id)
|
|
}}
|
|
>
|
|
<X className="h-3 w-3" />
|
|
</button>
|
|
</div>
|
|
</ContextMenuTrigger>
|
|
<ContextMenuContent>
|
|
<ContextMenuItem onSelect={() => startRename(tab.id, tab.title)}>
|
|
{t("rename")}
|
|
</ContextMenuItem>
|
|
<ContextMenuSeparator />
|
|
<ContextMenuItem onSelect={() => closeTerminal(tab.id)}>
|
|
{t("close")}
|
|
</ContextMenuItem>
|
|
<ContextMenuItem
|
|
onSelect={() => closeOtherTerminals(tab.id)}
|
|
disabled={tabs.length <= 1}
|
|
>
|
|
{t("closeOthers")}
|
|
</ContextMenuItem>
|
|
<ContextMenuItem onSelect={() => closeAllTerminals()}>
|
|
{t("closeAll")}
|
|
</ContextMenuItem>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
))}
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-6 w-6 shrink-0"
|
|
onClick={() => createTerminal()}
|
|
disabled={!canCreateTerminal}
|
|
>
|
|
<Plus className="h-3 w-3" />
|
|
</Button>
|
|
</span>
|
|
</TooltipTrigger>
|
|
{!canCreateTerminal && (
|
|
<TooltipContent side="top">{t("openFolderFirst")}</TooltipContent>
|
|
)}
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-6 w-6 shrink-0 ml-auto"
|
|
onClick={toggle}
|
|
title={t("hideTerminal", {
|
|
shortcut: formatShortcutLabel(shortcuts.toggle_terminal, isMac),
|
|
})}
|
|
>
|
|
<Minus className="h-3 w-3" />
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|