@@ -4,11 +4,12 @@ import { useOperator } from "@/contexts/OperatorContext";
44import { supabase } from "@/integrations/supabase/client" ;
55import { Card } from "@/components/ui/card" ;
66import { Button } from "@/components/ui/button" ;
7- import { Clock , Square } from "lucide-react" ;
7+ import { Clock , Square , ChevronDown , ChevronUp } from "lucide-react" ;
88import { stopTimeTracking } from "@/lib/database" ;
99import { toast } from "sonner" ;
1010import { formatDistanceToNow } from "date-fns" ;
1111import { useTranslation } from "react-i18next" ;
12+ import { cn } from "@/lib/utils" ;
1213
1314interface ActiveEntry {
1415 id : string ;
@@ -32,6 +33,7 @@ export default function CurrentlyTimingWidget() {
3233 const operatorId = activeOperator ?. id || profile ?. id ;
3334 const [ activeEntries , setActiveEntries ] = useState < ActiveEntry [ ] > ( [ ] ) ;
3435 const [ , setTick ] = useState ( 0 ) ;
36+ const [ isCollapsed , setIsCollapsed ] = useState ( false ) ;
3537
3638 const loadActiveEntries = useCallback ( async ( ) => {
3739 if ( ! operatorId ) return ;
@@ -108,37 +110,71 @@ export default function CurrentlyTimingWidget() {
108110 if ( activeEntries . length === 0 ) return null ;
109111
110112 return (
111- < Card className = "p-4 bg-active-work/5 border-active-work/30" >
112- < div className = "flex items-center gap-2 mb-3" >
113- < Clock className = "h-5 w-5 text-active-work" />
114- < h3 className = "font-semibold" > { t ( "operations.currentlyTiming" ) } </ h3 >
115- </ div >
116- < div className = "space-y-2" >
117- { activeEntries . map ( ( entry ) => (
118- < div
119- key = { entry . id }
120- className = "flex items-center justify-between p-3 bg-background rounded-lg border"
121- >
122- < div className = "flex-1 min-w-0" >
123- < div className = "font-medium truncate" > { entry . operation . operation_name } </ div >
124- < div className = "text-sm text-muted-foreground" >
125- { t ( "operations.job" ) } { entry . operation . part . job . job_number } • { entry . operation . part . part_number }
126- </ div >
127- < div className = "text-xs text-muted-foreground mt-1" >
128- { t ( "operations.started" ) } { formatDistanceToNow ( new Date ( entry . start_time ) , { addSuffix : true } ) }
113+ < Card className = "bg-active-work/5 border-active-work/30 overflow-hidden" >
114+ { /* Header - always visible, clickable to toggle */ }
115+ < button
116+ onClick = { ( ) => setIsCollapsed ( ! isCollapsed ) }
117+ className = "w-full flex items-center justify-between p-3 hover:bg-active-work/10 transition-colors"
118+ >
119+ < div className = "flex items-center gap-2" >
120+ < Clock className = "h-4 w-4 text-active-work animate-pulse" />
121+ < span className = "font-semibold text-sm" > { t ( "operations.currentlyTiming" ) } </ span >
122+ < span className = "text-xs text-active-work bg-active-work/20 px-1.5 py-0.5 rounded-full" >
123+ { activeEntries . length }
124+ </ span >
125+ </ div >
126+ < div className = "flex items-center gap-2" >
127+ { /* Show first entry summary when collapsed */ }
128+ { isCollapsed && activeEntries [ 0 ] && (
129+ < span className = "text-xs text-muted-foreground truncate max-w-[200px]" >
130+ { activeEntries [ 0 ] . operation . operation_name }
131+ </ span >
132+ ) }
133+ { isCollapsed ? (
134+ < ChevronDown className = "h-4 w-4 text-muted-foreground" />
135+ ) : (
136+ < ChevronUp className = "h-4 w-4 text-muted-foreground" />
137+ ) }
138+ </ div >
139+ </ button >
140+
141+ { /* Content - collapsible */ }
142+ < div
143+ className = { cn (
144+ "transition-all duration-200 ease-in-out overflow-hidden" ,
145+ isCollapsed ? "max-h-0 opacity-0" : "max-h-[500px] opacity-100"
146+ ) }
147+ >
148+ < div className = "px-3 pb-3 space-y-2" >
149+ { activeEntries . map ( ( entry ) => (
150+ < div
151+ key = { entry . id }
152+ className = "flex items-center justify-between p-3 bg-background rounded-lg border"
153+ >
154+ < div className = "flex-1 min-w-0" >
155+ < div className = "font-medium truncate text-sm" > { entry . operation . operation_name } </ div >
156+ < div className = "text-xs text-muted-foreground" >
157+ { t ( "operations.job" ) } { entry . operation . part . job . job_number } • { entry . operation . part . part_number }
158+ </ div >
159+ < div className = "text-[10px] text-muted-foreground mt-1" >
160+ { t ( "operations.started" ) } { formatDistanceToNow ( new Date ( entry . start_time ) , { addSuffix : true } ) }
161+ </ div >
129162 </ div >
163+ < Button
164+ variant = "outline"
165+ size = "sm"
166+ onClick = { ( e ) => {
167+ e . stopPropagation ( ) ;
168+ handleStop ( entry . operation_id ) ;
169+ } }
170+ className = "gap-1.5 ml-3 h-8 text-xs"
171+ >
172+ < Square className = "h-3 w-3" />
173+ { t ( "operations.stop" ) }
174+ </ Button >
130175 </ div >
131- < Button
132- variant = "outline"
133- size = "sm"
134- onClick = { ( ) => handleStop ( entry . operation_id ) }
135- className = "gap-2 ml-4"
136- >
137- < Square className = "h-4 w-4" />
138- { t ( "operations.stop" ) }
139- </ Button >
140- </ div >
141- ) ) }
176+ ) ) }
177+ </ div >
142178 </ div >
143179 </ Card >
144180 ) ;
0 commit comments