1-
1+ import { useState , useEffect } from "react" ;
22import { Button } from "@/components/ui/button" ;
3- import { GitBranch , Plus , RefreshCw } from "lucide-react" ;
3+ import { GitBranch , Plus , RefreshCw , ChevronDown , ChevronUp } from "lucide-react" ;
44import { cn , pathsEqual } from "@/lib/utils" ;
55import type { WorktreePanelProps , WorktreeInfo } from "./types" ;
66import {
@@ -13,6 +13,8 @@ import {
1313} from "./hooks" ;
1414import { WorktreeTab } from "./components" ;
1515
16+ const WORKTREE_PANEL_COLLAPSED_KEY = "worktree-panel-collapsed" ;
17+
1618export function WorktreePanel ( {
1719 projectPath,
1820 onCreateWorktree,
@@ -81,6 +83,27 @@ export function WorktreePanel({
8183 features,
8284 } ) ;
8385
86+ // Collapse state with localStorage persistence
87+ const [ isCollapsed , setIsCollapsed ] = useState ( ( ) => {
88+ if ( typeof window === "undefined" ) return false ;
89+ const saved = localStorage . getItem ( WORKTREE_PANEL_COLLAPSED_KEY ) ;
90+ return saved === "true" ;
91+ } ) ;
92+
93+ useEffect ( ( ) => {
94+ localStorage . setItem ( WORKTREE_PANEL_COLLAPSED_KEY , String ( isCollapsed ) ) ;
95+ } , [ isCollapsed ] ) ;
96+
97+ const toggleCollapsed = ( ) => setIsCollapsed ( ( prev ) => ! prev ) ;
98+
99+ // Get the currently selected worktree for collapsed view
100+ const selectedWorktree = worktrees . find ( ( w ) => {
101+ if ( currentWorktree === null || currentWorktree === undefined || currentWorktree . path === null ) {
102+ return w . isMain ;
103+ }
104+ return pathsEqual ( w . path , currentWorktreePath ) ;
105+ } ) ;
106+
84107 const isWorktreeSelected = ( worktree : WorktreeInfo ) => {
85108 return worktree . isMain
86109 ? currentWorktree === null ||
@@ -106,8 +129,45 @@ export function WorktreePanel({
106129 return null ;
107130 }
108131
132+ // Collapsed view - just show current branch and toggle
133+ if ( isCollapsed ) {
134+ return (
135+ < div className = "flex items-center gap-2 px-4 py-1.5 border-b border-border bg-glass/50 backdrop-blur-sm" >
136+ < Button
137+ variant = "ghost"
138+ size = "sm"
139+ className = "h-6 w-6 p-0 text-muted-foreground hover:text-foreground"
140+ onClick = { toggleCollapsed }
141+ title = "Expand worktree panel"
142+ >
143+ < ChevronDown className = "w-4 h-4" />
144+ </ Button >
145+ < GitBranch className = "w-4 h-4 text-muted-foreground" />
146+ < span className = "text-sm text-muted-foreground" > Branch:</ span >
147+ < span className = "text-sm font-mono font-medium" >
148+ { selectedWorktree ?. branch ?? "main" }
149+ </ span >
150+ { selectedWorktree ?. hasChanges && (
151+ < span className = "inline-flex items-center justify-center h-4 min-w-[1rem] px-1 text-[10px] font-medium rounded border bg-amber-500/20 text-amber-600 dark:text-amber-400 border-amber-500/30" >
152+ { selectedWorktree . changedFilesCount ?? "!" }
153+ </ span >
154+ ) }
155+ </ div >
156+ ) ;
157+ }
158+
159+ // Expanded view - full worktree panel
109160 return (
110161 < div className = "flex items-center gap-2 px-4 py-2 border-b border-border bg-glass/50 backdrop-blur-sm" >
162+ < Button
163+ variant = "ghost"
164+ size = "sm"
165+ className = "h-6 w-6 p-0 text-muted-foreground hover:text-foreground"
166+ onClick = { toggleCollapsed }
167+ title = "Collapse worktree panel"
168+ >
169+ < ChevronUp className = "w-4 h-4" />
170+ </ Button >
111171 < GitBranch className = "w-4 h-4 text-muted-foreground" />
112172 < span className = "text-sm text-muted-foreground mr-2" > Branch:</ span >
113173
0 commit comments