I need a very thorough investigation of the lightbox layout props system. Please explore the following comprehensively:
Read the full fileuseLightboxLayoutProps.ts - find it with glob first, then read every line
Read the three contexts that were created to replace parts of it:
LightboxStateContext (find and read)
ImageEditContext (find and read)
VideoEditContext (find and read)
Read ImageLightbox.tsx and VideoLightbox.tsx - find them and read them fully
Find all consumers of useLightboxLayoutProps - everywhere it's imported/used
Find the type definition for the props it returns (the return type / interface)
Find what provides the contexts - where LightboxStateContext, ImageEditContext, VideoEditContext providers are rendered
For each file, report:
Full file path
Line count
[REDACTED]
How it relates to the other files
Be extremely thorough - read every file completely, don't skip any. I need to understand the full picture of how props flow from the lightbox components through useLightboxLayoutProps to the layout.
Assistant
I'll conduct a thorough investigation of the lightbox layout props system. Let me start by finding and reading all the relevant files.
Assistant
Now let me read all these files completely.
Assistant
Now let me find all consumers of useLightboxLayoutProps and find the return type interface.
Assistant
Now let me search for where the contexts are provided (the Provider components).
Assistant
Now let me find where the LightboxLayout component is defined to understand how it uses these props.
Assistant
Now let me search for any other consumers or related components to complete the picture.
Assistant
User
I need to understand how VideoLightbox.tsx calls useLightboxLayoutProps. Read the full file at /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/VideoLightbox.tsx.
For the call to useLightboxLayoutProps, I need to know:
Which props are passed with real values vs stubs
The exact line range of the call
What video-specific values are passed
Also read /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/VideoEditPanel.tsx to understand what specialized props it receives vs what it reads from context.
Assistant
I'll read both files to understand how VideoLightbox uses useLightboxLayoutProps and how VideoEditPanel integrates.
User
I need to understand MediaDisplayWithCanvas's full props interface and how it's called.
Read the full file at /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/MediaDisplayWithCanvas.tsx - I need its complete props interface and which props are used for what purpose.
Search for all usages of useImageEditSafe and useVideoEditSafe in files under /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/ - I need to know which components already consume from these contexts. List each file and which hooks it uses.
Read /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/WorkflowControlsBar.tsx and /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/WorkflowControls.tsx - just the props interfaces, first 60 lines should be enough.
For MediaDisplayWithCanvas, categorize its props into:
Core display props (url, video, dimensions)
Edit mode props (brush, annotation, reposition - things that could come from ImageEditContext)
Layout-specific props (variant, className, etc.)
User
I need to understand the ControlsPanel props chain for Phase 4 planning.
Read /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/InfoPanel.tsx - just the props interface (first 80 lines should be enough) to understand what InfoPanel receives as props vs reads from context.
Read /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/VideoEditPanel.tsx - just the props interface and the first section showing context usage (first 100 lines)
Read the ImageLightbox.tsx section where it builds the imageEditValue for context (search for "imageEditValue" around lines 761-921):
/Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/ImageLightbox.tsx
For each component, report:
What it receives via props
What it reads from context hooks
What would change if more state moved to context
Assistant
I'll help you understand MediaDisplayWithCanvas's props interface and the usage of edit contexts. Let me gather this information.
Assistant
I'll analyze the props chain for the ControlsPanel components to help with Phase 4 planning.
Assistant
Now let me get the files that use these hooks to see the full pattern.
Assistant
Now let me search for the imageEditValue construction in ImageLightbox.tsx.
Assistant
Now let me check what context hooks these components are using to understand the full picture.
Assistant
Assistant
Assistant
User
Assistant
I'll start by thoroughly exploring all the files mentioned to understand the current state, then produce a precise execution plan.
Assistant
Now let me read the remaining key files to understand the full picture.
Assistant
Now let me examine the remaining key files - MediaDisplayWithCanvas, ControlsPanel, EditModePanel, and FloatingToolControls.
Assistant
Now let me check the EditModePanel and InfoPanel to understand what they receive from props vs. context.
Assistant
Now let me also look at the start of ImageLightbox to understand where the hook values come from (especially what's supplied to the ImageEditProvider).
Assistant
Now I have a thorough understanding of the full system. Let me verify one more key area - the EditPanelLayout to see if it reads from context or props.
Assistant
Perfect! Now I have all the information needed. Let me create a comprehensive report.
Comprehensive Investigation Report: Lightbox Layout Props System
Overview
The lightbox system uses a layered architecture with contexts and a centralized props builder hook to manage state flow from the lightbox components through to the unified layout.
Return type: UseLightboxLayoutPropsReturn with single property layoutProps: LightboxLayoutProps
Purpose: Central props builder that consolidates 284 individual values from ImageLightbox/VideoLightbox into a unified LightboxLayoutProps object. It performs composition of sub-objects like:
controlsPanelProps (lines 294-378)
workflowBarProps (lines 381-411)
floatingToolProps (lines 414-424)
workflowControlsProps (lines 427-431)
Final layoutProps assembly (lines 434-509)
Key Design Decision: Props are conditionally included based on showPanel flag - panel-specific props only included when showPanel=true, centered-layout props when false.
2. Three Context System (Created to Replace Parts of Props)
useLightboxCoreSafe() → Core state (onClose, readOnly, isMobile, etc.)
useLightboxMediaSafe() → Media state (media object, URLs, dimensions)
useLightboxVariantsSafe() → Variant state (list, activeVariant, actions)
useLightboxNavigationSafe() → Navigation state (arrows, swipe handlers)
Relationship: Provides shared state to deeply-nested components without prop drilling. Organized into 4 logical domains (Core, Media, Variants, Navigation) with focused consumer hooks.
EditFormState - Prompts, strengths, LoRA, model selection, advanced settings
GenerationStatusState - Loading/success flags for all edit modes
Relationship: Only provided by ImageLightbox (not VideoLightbox). Consolidates all image-specific edit state. The composed flat shape makes destructuring natural for consumers.
Centered layout (no panel): !showPanel → Gallery view (lines 464-706)
Relationship to Props: Receives 186 props from LightboxLayoutProps, but also reads state directly from contexts to reduce prop drilling for common values like media, variants, isInpaintMode.
Purpose: Consolidates provider wrapping. Both ImageLightbox and VideoLightbox compute their LightboxStateValue, then pass to this component for consistent provider composition.
ImageLightbox/VideoLightbox
↓ (builds lightboxStateValue via useLightboxStateValue)
↓ (builds imageEditValue / videoEditValue)
↓
LightboxProviders (provides LightboxStateContext)
↓
ImageEditProvider / VideoEditProvider
↓
LightboxLayout + all descendants
↓ (consume via useLightboxCoreSafe, useImageEditSafe, etc.)
9. Key Findings
Dual System: Props + Contexts working in parallel. useLightboxLayoutProps still exists with 284 inputs and 186 outputs, but many values are now also available via contexts.
Redundancy: Some values flow through BOTH systems:
Example: media - passed as prop to LightboxLayout, also available via useLightboxMediaSafe()
Example: isInpaintMode - in layoutProps, also in useImageEditSafe()
Context Specialization:
LightboxStateContext: Shared state (core, media, variants, navigation) - provided to both image and video
Safe Hooks Pattern: All context hooks have "Safe" versions that return defaults when used outside provider, preventing crashes in Storybook or isolated components.
Massive Input Surface: useLightboxLayoutProps takes 284 distinct inputs, suggesting it could be further decomposed or that more values should migrate to contexts.
Conditional Composition: Hook conditionally includes props based on showPanel - panel props only when true, centered-layout props only when false.
Analysis of VideoLightbox.tsx and useLightboxLayoutProps
1. The useLightboxLayoutProps Call (Lines 818-1036)
Location: Lines 818-1036 in VideoLightbox.tsx
The call to useLightboxLayoutProps is a massive prop-passing operation where VideoLightbox threads through nearly every piece of state and handler it has.
VideoLightbox passes video-specific specialized props directly to VideoEditPanel (trim state, video editing manager, regenerate props, enhance props) while allowing VideoEditPanel to read shared state (mode, variants, core) from context. This keeps the specialized video functionality explicit while leveraging context for shared patterns.
The image edit stubs in useLightboxLayoutProps exist because the hook returns a unified interface that both ImageLightbox and VideoLightbox use, but VideoLightbox doesn't need the image-specific functionality.
Analysis: MediaDisplayWithCanvas Props Interface and Edit Context Usage
Based on my analysis of the code, here's the complete breakdown:
Variants (6 items from useLightboxVariantsSafe): pendingTaskCount, unviewedVariantCount, onMarkAllViewed, onLoadVariantImages, currentSegmentImages, plus it creates its own variantsSectionRef
Note: This component receives many variant props that could be read from context instead. It's doing partial context usage (some variant state from props, some from context).
What would change if more state moved to context:
Variant props (11 props) could all come from context - currently there's inconsistent split
Would reduce from 18 props to 7 (variant, onClose, onExitEditMode, hideInfoEditToggle, simplifiedHeader, modeSelector, children, taskId)
The variantsSectionRef it creates could move to context too
4. ImageEditContext (imageEditValue in ImageLightbox.tsx, lines 761-920)
What's in context (87 items total):
Mode state (3): isInpaintMode, isMagicEditMode, isSpecialEditMode, editMode
Create TaskDetailsContext - eliminate 9 props from InfoPanel
Create TrimStateContext - eliminate 13 props from VideoEditPanel
Create EnhanceStateContext - eliminate 6 props from VideoEditPanel
Consolidate variant props - EditPanelLayout should read all variant state from context (eliminate 11 props)
Per-pair data context - currentMediaId, currentShotId, replaceImages could move to core/media context
Key insight:
VideoEditPanel already has a props-first pattern for standalone usage (the optional coreState, videoEditState, variantsState overrides). This pattern should be preserved when moving trim/enhance to context - context values should be the default, but props should still be able to override for standalone usage.
Design a detailed, step-by-step execution plan for refactoring the lightbox layout props system. I'll provide the comprehensive analysis, and I need you to produce a precise plan with exact file paths, line ranges, and changes.
Background
useLightboxLayoutProps.ts is a 513-line hook with a 284-property input interface. It was written before three contexts existed:
These props appear in UseLightboxLayoutPropsInput (lines 23-284) and are passed by callers, but are NEVER referenced in the hook body (lines 290-512). They were migrated to contexts but the interface wasn't cleaned up.
Plan: Remove these from UseLightboxLayoutPropsInput interface. Remove corresponding properties from the call sites in ImageLightbox.tsx (lines 1009-1231) and VideoLightbox.tsx (lines 818-1036).
Phase 2: Migrate LayoutEditModeProps to ImageEditContext
LayoutEditModeProps (types.ts lines 44-79) has 35 props that duplicate ImageEditContext. Currently:
LightboxLayout reads some from context (isInpaintMode, isSpecialEditMode, editMode) and some from props (isAnnotateMode, brushStrokes, etc.)
MediaDisplayWithCanvas receives ALL edit props via props (25 edit-related props)
FloatingToolControls already reads from ImageEditContext (good pattern to follow)
Plan:
Add missing items to ImageEditContext if needed:
onStrokeComplete, onStrokesChange, onSelectionChange, onTextModeHint - these are callbacks from useInpainting, need to check if they're in context
Make MediaDisplayWithCanvas consume edit state from useImageEditSafe() instead of props
Make LightboxLayout consume ALL edit state from context (remove dual-path reads)
Remove LayoutEditModeProps from LightboxLayoutProps type
Remove corresponding inputs from useLightboxLayoutProps
Remove corresponding values from ImageLightbox/VideoLightbox call sites
Note: Some items like repositionDragHandlers, getTransformStyle, strokeOverlayRef, imageContainerRef are refs/callbacks that need careful handling. They should be added to ImageEditContext.
Actually, wait - looking at this more carefully, some of these are NOT in ImageEditContext currently:
ImageEditContext has: brush state, annotation state, reposition transform (read-only), form state, generation status
ImageEditContext does NOT have: onStrokeComplete, onStrokesChange, onSelectionChange, onTextModeHint, strokeOverlayRef, getDeleteButtonPosition, handleToggleFreeForm, handleDeleteSelected, isRepositionDragging, repositionDragHandlers, getTransformStyle, imageContainerRef, isFlippedHorizontally, isSaving
So Phase 2 requires expanding ImageEditContext with these callback/ref items. This is a significant change.
Phase 3: Migrate LayoutVideoEditProps to VideoEditContext
LayoutVideoEditProps (types.ts lines 17-39) has ~10 props. Some are already in VideoEditContext, but it's missing:
Have LightboxLayout and video display components consume from useVideoEditSafe()
Remove LayoutVideoEditProps from LightboxLayoutProps
Remove corresponding inputs from useLightboxLayoutProps
Remove ImageLightbox's ~30 video stub props
Phase 4: Extract ControlsPanel props to dedicated hook
After phases 1-3, controlsPanelProps (~60 fields) is the remaining bulk. It's built in useLightboxLayoutProps and passed through LightboxLayout to ControlsPanel.
Plan:
Create useControlsPanelProps() hook that ControlsPanel calls directly
It reads shared state from contexts and receives only specialized props (handlers, managers)
ControlsPanel gets its specialized props directly rather than through the layout
Remove controlsPanelProps from LightboxLayoutProps and useLightboxLayoutProps
This may require ControlsPanel to receive some props directly from parent (the specialized handlers) or a new "specialized props" context for the things that can't come from existing contexts.
After 1-4, the hook only builds workflowBarProps, floatingToolProps, workflowControlsProps, and does conditional showPanel switching. At this point it's a thin wrapper that could:
Stay as-is (simple)
Move into LightboxLayout
Be replaced by smaller hooks
Constraints
This is a TypeScript + React codebase
All contexts use "Safe" hooks with defaults for use outside providers
The system uses a props-first with context fallback pattern in some components (EditModePanel, VideoEditPanel) - this pattern should be preserved for standalone usage
Verification: npx tsc --noEmit for type checking, visual testing for runtime
Please design the step-by-step plan with exact details for each phase. Be specific about what code changes in which files.
Now I have a comprehensive understanding of the entire system. Let me compile the detailed execution plan.
Detailed Execution Plan: Refactoring the Lightbox Layout Props System
This plan addresses the redundancy in useLightboxLayoutProps.ts (513 LOC, 284-property input interface) across five phases, each independently verifiable with npx tsc --noEmit.
Phase 1: Remove Dead Input Props (~30 props)
Goal: Remove props from UseLightboxLayoutPropsInput that are passed by callers but never read in the hook body (lines 290-512).
Verification method: Every prop listed below was confirmed absent from the hook body (lines 290-512) by searching the code. They exist only in the interface declaration (lines 23-284).
All six video mode handlers (lines 91-96): handleEnterVideoTrimMode, handleEnterVideoReplaceMode, handleEnterVideoRegenerateMode, handleEnterVideoEnhanceMode, handleExitVideoEditMode, handleEnterVideoEditMode
All generation status (lines 169-182, 193-194) -- already counted above
handleExitMagicEditMode (line 173)
Info panel name props (lines 208-211): 4 props
showNavigation (line 225) -- NOT in hook body
hasNext (line 226), hasPrevious (line 227) -- NOT in hook body
Wait, many of these "core/navigation" items are also dead because LightboxLayout reads them from context, not from layoutProps. Let me count precisely.
The confirmed dead input props (not referenced in hook body lines 290-512):
Lines 854, 870-876 (isInVideoEditMode + all 6 video mode handlers)
Lines 889-926 (edit mode stubs including setEditMode, setIsInpaintMode, entire edit form stubs, inpaintPanelPosition, etc.)
Lines 927-969 (entire edit form/generation status stubs)
Lines 973-976 (generationName stubs)
Lines 989-994 (navigation props)
Step 1.4: Also remove dead import types
In useLightboxLayoutProps.ts, remove import types that are no longer used after the interface shrinks:
Line 10: GenerationVariant (if no longer needed)
Line 16: ImageTransform (still needed for repositionTransform)
Line 17: EditAdvancedSettings (still needed in controlsPanelProps)
Line 18: SourceVariantData (still needed)
Check each import after the removals.
Step 1.5: Remove unused variables from callers
In ImageLightbox.tsx, after removing props from the hook call, some local variables may become unused:
Lines 990-993: generationName, isEditingGenerationName, setIsEditingGenerationName, handleGenerationNameChange -- remove these
Lines 996-997: isFlippedHorizontally, isSaving -- these are still passed as layoutProps inputs (used in hook body), so KEEP
In VideoLightbox.tsx:
Lines 809-812: same generation name stubs -- remove
Verification: npx tsc --noEmit should pass. No runtime behavior changes since removed props were never read.
Phase 2: Migrate LayoutEditModeProps to ImageEditContext
Goal: Move the 35-property LayoutEditModeProps (types.ts lines 44-79) from props to context. This means LightboxLayout and MediaDisplayWithCanvas will read edit mode state from useImageEditSafe() instead of props.
Current state of ImageEditContext (from /Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/contexts/ImageEditContext.tsx): Contains mode state, brush state, annotation state, reposition transform (read-only), form state, generation status. Does NOT contain:
Add default values for each new sub-interface in the EMPTY constants. The defaults use no-ops and { current: null } refs, matching what VideoLightbox currently passes as stubs.
Add needed imports: StrokeOverlayHandle from ../components/StrokeOverlay, React (already imported).
Step 2.2: Populate the new context fields in ImageLightbox
Currently at line 56, the component already has const imageEdit = useImageEditSafe(); and destructures isInpaintMode, isSpecialEditMode, editMode from it (line 62).
Expand that destructuring to include everything from LayoutEditModeProps:
In the final layoutProps build (lines 434-509), remove:
Lines 446-474 (isInpaintMode through isSaving)
Lines 478-482 (onRepositionRotationChange/repositionRotation/onRepositionScaleChange/repositionScale) -- WAIT, these are still needed by MediaDisplayWithCanvas. But they come from repositionTransform which is now in context...
Actually, looking more carefully: repositionRotation and repositionScale (lines 479, 482) are separate props derived from input.repositionTransform. They are used by LightboxLayout for passing to MediaDisplayWithCanvas. Since MediaDisplayWithCanvas does NOT use context yet (Phase 2 migrates LightboxLayout, not MediaDisplayWithCanvas), we need to decide: do we also migrate MediaDisplayWithCanvas in Phase 2, or keep these specific pass-throughs?
Decision: In Phase 2, we also make MediaDisplayWithCanvas read from context for the edit-related props. This is the clean approach because MediaDisplayWithCanvas is always rendered inside the provider tree.
Step 2.6: Make MediaDisplayWithCanvas read edit props from context
annotationMode -> imageEdit.annotationMode (conditional on editMode)
selectedShapeId -> (not in context... wait, it IS -- AnnotationToolState.selectedShapeId)
isAnnotateMode -> imageEdit.isAnnotateMode
onStrokeComplete -> imageEdit.onStrokeComplete
onStrokesChange -> imageEdit.onStrokesChange
onSelectionChange -> imageEdit.onSelectionChange
onTextModeHint -> imageEdit.onTextModeHint
strokeOverlayRef -> imageEdit.strokeOverlayRef
For repositionTransformStyle, currently LightboxLayout computes it as getTransformStyle(). In context, getTransformStyle returns CSSProperties. MediaDisplayWithCanvas can call imageEdit.getTransformStyle() directly.
For onRepositionRotationChange, repositionRotation, onRepositionScaleChange, repositionScale -- these are used by MediaDisplayWithCanvas for corner rotation handles and zoom buttons. They come from setRotation and repositionTransform via the hook. Since setRotation and setScale are now in context (RepositionInteractionState), and repositionTransform is already in context (RepositionState), MediaDisplayWithCanvas can read them from context.
In LightboxLayout, the <MediaDisplayWithCanvas> call (lines 194-234) currently passes all edit props explicitly. After Phase 2, remove all edit-related props from this JSX call. MediaDisplayWithCanvas reads them from context.
The remaining props to pass explicitly:
jsx
<MediaDisplayWithCanvas
effectiveImageUrl={isVideo ? effectiveVideoUrl : effectiveMediaUrl}
thumbUrl={activeVariant?.thumbnail_url || media.thumbUrl}
isVideo={isVideo}
imageContainerRef={...} // now from context, remove this prop
onImageLoad={setImageDimensions}
onVideoLoadedMetadata={...}
variant={mediaDisplayVariant}
containerClassName={mediaDisplayContainerClassName}
tasksPaneWidth={...}
debugContext={mediaDisplayDebugContext}
imageDimensions={effectiveImageDimensions}
/>
Step 2.8: Remove edit mode props from useLightboxLayoutProps input and output
In useLightboxLayoutProps.ts:
Remove all edit mode properties from UseLightboxLayoutPropsInput that are no longer forwarded: isInpaintMode, isAnnotateMode, isSpecialEditMode, editMode, brushStrokes, isEraseMode, setIsEraseMode, brushSize, setBrushSize, annotationMode, setAnnotationMode, selectedShapeId, onStrokeComplete, onStrokesChange, onSelectionChange, onTextModeHint, strokeOverlayRef, handleUndo, handleClearMask, getDeleteButtonPosition, handleToggleFreeForm, handleDeleteSelected, isRepositionDragging, repositionDragHandlers, getTransformStyle, imageContainerRef, isFlippedHorizontally, isSaving, repositionTransform, setTranslateX, setTranslateY, setScale, setRotation, toggleFlipH, toggleFlipV, resetTransform
Remove them from the layoutProps object (lines 446-482)
Remove them from the useMemo dependency arrays
Remove them from the floatingToolProps build (wait -- floatingToolProps uses setScale, setRotation, toggleFlipH, toggleFlipV, resetTransform, repositionTransform). These now come from context, but floatingToolProps is passed to FloatingToolControls which reads reposition handlers from props (not context). We have two options:
a. Make FloatingToolControls also read from context (it already reads most things from context)
b. Keep floatingToolProps but build it from context inside LightboxLayout
Option (a) is cleaner. FloatingToolControls already reads from ImageEditContext. Its only props are the reposition handlers (repositionTransform, onRepositionScaleChange, etc.). If we add these to context, FloatingToolControls needs zero props beyond variant.
But wait -- FloatingToolControls already receives these as props specifically because they're "specialized reposition handlers (not contextual state)" per its interface comment. Now that we're adding them to context, FloatingToolControls CAN read them from context.
Remove all props except variant. Update FloatingToolControlsProps to only have variant.
Step 2.10: Remove floatingToolProps from useLightboxLayoutProps and LightboxLayoutProps
In useLightboxLayoutProps.ts: remove the floatingToolProps useMemo (lines 414-424) and its inclusion in layoutProps
In types.ts: remove floatingToolProps?: LayoutFloatingToolPropsSimple; from LightboxLayoutProps and the LayoutFloatingToolPropsSimple interface
In LightboxLayout.tsx: the FloatingToolControls rendering (line 368-378) simplifies to just <FloatingToolControls variant={floatingToolVariant} />
Step 2.11: Remove edit stubs from call sites
In ImageLightbox.tsx (lines 1080-1118) and VideoLightbox.tsx (lines 885-923): remove all edit mode props from the useLightboxLayoutProps({...}) call that were removed from the interface.
Verification: npx tsc --noEmit. Visually test inpaint mode, annotate mode, and reposition mode in the image lightbox.
Phase 3: Migrate LayoutVideoEditProps to VideoEditContext
Goal: Move the video edit props from LightboxLayoutProps to context.
Current state of VideoEditContext: Has mode state, mode handlers, trim state (minus save handlers), duration/playback, enhance settings. Does NOT have:
trimVideoRef (ref)
videoEditing (the video editing manager object)
isVideoTrimModeActive / isVideoEditModeActive (derived booleans -- these can be computed from videoEditSubMode)
Step 3.5: Remove video edit props from useLightboxLayoutProps
In useLightboxLayoutProps.ts, remove from input interface and from layoutProps output:
isVideoTrimModeActive, isVideoEditModeActive, trimVideoRef, trimState (the one in layoutProps), setVideoDuration, setTrimCurrentTime, videoEditing (the one in layoutProps)
Note: trimState, trimVideoRef, videoEditing etc. are ALSO used in controlsPanelProps. Those must stay in the input until Phase 4 addresses controlsPanelProps.
Step 3.6: Remove ImageLightbox's video stub props from the hook call
In ImageLightbox (lines 1042-1061): These video stubs were already partially removed in Phase 1. Now remove the remaining ones that were in layoutProps but are now from context:
isVideoTrimModeActive: false (line 1043)
isVideoEditModeActive: false (line 1044)
trimVideoRef: { current: null } (line 1046)
trimState (line 1047) -- remove from layoutProps section but keep if used in controlsPanelProps
setVideoDuration (line 1058)
setTrimCurrentTime (line 1059)
videoEditing: null (line 1061) -- remove from layoutProps section but keep for controlsPanelProps
Verification: npx tsc --noEmit. Test video trim and replace modes visually.
Phase 4: Extract ControlsPanel Props to Dedicated Pattern
Goal: The controlsPanelProps blob (~60 fields built in useLightboxLayoutProps lines 294-378) is the remaining bulk. Move its construction closer to where it's consumed.
Approach: Instead of creating a new hook, pass controlsPanelProps as a direct prop to LightboxLayout, built inline in the callers (ImageLightbox, VideoLightbox). This eliminates the indirection through useLightboxLayoutProps while keeping the prop-passing pattern that ControlsPanel needs.
Step 4.1: Add controlsPanelProps as a direct prop
Build the controlsPanelProps object directly in ImageLightbox and VideoLightbox, right before the <LightboxLayout> call, rather than routing through useLightboxLayoutProps. This means the controlsPanelProps useMemo moves from the hook into each caller.
In ImageLightbox.tsx: Build a controlsPanelProps useMemo before the JSX return, using the same values currently passed to the hook (they're all local variables in ImageLightbox anyway).
In VideoLightbox.tsx: Same approach.
Then pass controlsPanelProps directly to <LightboxLayout controlsPanelProps={showPanel ? controlsPanelProps : undefined}>.
Step 4.2: Remove controlsPanelProps from useLightboxLayoutProps
In useLightboxLayoutProps.ts, remove:
The entire controlsPanelProps useMemo (lines 294-378)
All input props that were only used for controlsPanelProps (after Phases 1-3, check each one)
Remove controlsPanelProps from the layoutProps output
Step 4.3: Update LightboxLayoutProps type
The controlsPanelProps field stays in LightboxLayoutProps (types.ts line 176) -- it's just sourced differently now.
Verification: npx tsc --noEmit. Test all three panel modes (info, edit, video edit).
Decision: The hook is now small enough (~80 lines) to either:
Keep as a thin props-building utility (recommended: it still provides value by centralizing workflowBarProps construction)
Inline the workflowBarProps and workflowControlsProps construction into each caller
Recommendation: Keep the hook but rename it to useLightboxWorkflowProps since that's what it does now. Its input interface shrinks to ~30 workflow-related props plus showPanel, shouldShowSidePanel, effectiveTasksPaneOpen/Width, buttonGroupProps, adjacentSegments, segmentSlotMode.
Step 5.1: Rename and trim
Rename file and hook from useLightboxLayoutProps to useLightboxWorkflowProps. Update imports in ImageLightbox and VideoLightbox.
Trim the interface to only the workflow/layout-chrome props that are actually used.
Verification: npx tsc --noEmit. Full manual test of all lightbox modes.
Summary: Net Impact
Metric
Before
After Phase 1
After Phase 2
After Phase 3
After Phase 4
After Phase 5
Input interface props
~284
~210
~160
~150
~30
~30
Hook body LOC
~220
~220
~140
~130
~80
~80
LightboxLayoutProps fields
~80
~80
~45
~35
~35
~30
ImageLightbox call site lines
~220
~150
~80
~70
~50
~50
VideoLightbox call site lines
~220
~150
~80
~70
~50
~50
Risks and Mitigations
Context performance: Adding ~20 new fields to ImageEditContext means any change triggers re-renders in all consumers. Mitigation: The fields being added (refs, stable callbacks) rarely change. The useMemo in ImageLightbox already controls when the context value updates.
Props-first pattern in EditModePanel/VideoEditPanel: These components accept optional state overrides via coreState/imageEditState/variantsState props for standalone usage outside the provider tree. This pattern is unaffected -- the overrides still work because the context provides the same fields.
MediaDisplayWithCanvas outside provider: Currently only rendered inside LightboxLayout which is always inside the provider tree. The useImageEditSafe() hook returns safe defaults, so even if rendered outside, it won't crash.
Phase sequencing: Each phase is independently verifiable. Phase 1 has zero risk (removing dead code). Phases 2-3 are the core changes. Phase 4 is a refactor. Phase 5 is optional polish.
Critical Files for Implementation
/Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/hooks/useLightboxLayoutProps.ts - The hook being refactored; shrinks from 513 to ~80 lines across all phases
/Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/contexts/ImageEditContext.tsx - Must be expanded with canvas/reposition interaction state (Phase 2)
/Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/layouts/types.ts - LightboxLayoutProps type; LayoutEditModeProps and LayoutVideoEditProps removed
/Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/layouts/LightboxLayout.tsx - Consumer migrating from props to context for edit/video state
/Users/user_c042661f/Documents/reigh/src/shared/components/MediaLightbox/components/MediaDisplayWithCanvas.tsx - Currently props-only; migrates to context for edit state in Phase 2
handleSlotNavNext (line 228), handleSlotNavPrev (line 229) -- NOT in hook body