@@ -30,6 +30,10 @@ import { AgentSessionThreadPanel } from "@/features/channels/ui/AgentSessionThre
3030import { ChannelManagementAuxiliaryPanel } from "@/features/channels/ui/ChannelManagementAuxiliaryPanel" ;
3131import { IdleAuxiliaryPanel } from "@/features/channels/ui/IdleAuxiliaryPanel" ;
3232import { RightAuxiliaryPane } from "@/features/channels/ui/RightAuxiliaryPane" ;
33+ import {
34+ ThreadPanelSurface ,
35+ useThreadPanelSurface ,
36+ } from "@/features/channels/ui/ThreadPanelSurface" ;
3337import { ThreadViewModeToggle } from "@/features/channels/ui/ThreadViewModeToggle" ;
3438import { FocusThreadDrawer } from "@/features/channels/ui/FocusThreadDrawer" ;
3539import { THREAD_SURFACE_KEY } from "@/features/channels/lib/threadFocusLayout" ;
@@ -419,10 +423,10 @@ export const ChannelPane = React.memo(function ChannelPane({
419423 const isOverlay = useIsThreadPanelOverlay ( ) ;
420424 const useSplitAuxiliaryPane = ! isSinglePanelView && ! isOverlay ;
421425 const threadViewMode = useThreadViewMode ( ) ;
426+ const hasThreadSurface =
427+ Boolean ( threadHeadMessage ) || shouldShowThreadSkeleton ;
422428 const useFocusThreadDrawer =
423- threadViewMode === "focus" &&
424- useSplitAuxiliaryPane &&
425- ( Boolean ( threadHeadMessage ) || shouldShowThreadSkeleton ) ;
429+ threadViewMode === "focus" && useSplitAuxiliaryPane && hasThreadSurface ;
426430 const selectedAgent = React . useMemo (
427431 ( ) =>
428432 agentSessionSelection . resolveSelectedAgentSession ( {
@@ -435,19 +439,26 @@ export const ChannelPane = React.memo(function ChannelPane({
435439 ) ;
436440 const hasIdleAuxiliary =
437441 Boolean ( idleAuxiliaryPanel ) && Boolean ( onCloseIdleAuxiliaryPanel ) ;
442+ const priorityIdleAuxiliary = shouldPrioritizeIdleAuxiliary (
443+ idleAuxiliaryOverridesThread ,
444+ hasIdleAuxiliary ,
445+ ) ;
446+ const overlayIdleAuxiliaryOverThread =
447+ priorityIdleAuxiliary && hasThreadSurface && ! isOverlay ;
448+ const replaceThreadWithIdleAuxiliary =
449+ priorityIdleAuxiliary && hasThreadSurface && isOverlay ;
438450 const useFocusIdleDrawer = shouldUseFocusIdleDrawer ( {
439451 channelManagementOpen,
440452 hasAgentSession : Boolean ( activeChannel && selectedAgent ) ,
441453 hasIdleAuxiliaryPanel : Boolean ( idleAuxiliaryPanel ) ,
442454 hasIdlePanelCloseHandler : Boolean ( onCloseIdleAuxiliaryPanel ) ,
443455 hasProfilePanel : Boolean ( profilePanelPubkey ) ,
444- hasThreadSurface : Boolean ( threadHeadMessage ) || shouldShowThreadSkeleton ,
456+ hasThreadSurface,
457+ overrideThread : overlayIdleAuxiliaryOverThread ,
445458 useSplitAuxiliaryPane,
446459 } ) ;
447- const priorityIdleAuxiliary = shouldPrioritizeIdleAuxiliary (
448- idleAuxiliaryOverridesThread ,
449- hasIdleAuxiliary ,
450- ) ;
460+ const showIdleAuxiliaryOverThread =
461+ overlayIdleAuxiliaryOverThread && useFocusIdleDrawer ;
451462 const { channelIsCovered, markExitComplete } = useFocusDrawerPresence (
452463 useFocusThreadDrawer || useFocusIdleDrawer ,
453464 priorityIdleAuxiliary
@@ -456,6 +467,10 @@ export const ChannelPane = React.memo(function ChannelPane({
456467 ? onCloseThread
457468 : ( onCloseIdleAuxiliaryPanel ?? onCloseThread ) ,
458469 ) ;
470+ const threadSurface = useThreadPanelSurface (
471+ showIdleAuxiliaryOverThread ,
472+ markExitComplete ,
473+ ) ;
459474 const { changeThreadViewMode, layoutScrollTargetId, resolveScrollTarget } =
460475 useThreadViewModeSwitch ( {
461476 activeThreadHeadId : threadHeadMessage ?. id ?? null ,
@@ -506,26 +521,27 @@ export const ChannelPane = React.memo(function ChannelPane({
506521 ) : (
507522 < React . Fragment key = { options . key ?? testId } > { panel } </ React . Fragment >
508523 ) ;
509- const wrapThreadPanel = ( panel : React . ReactNode ) =>
510- useFocusThreadDrawer ? (
511- < FocusThreadDrawer
512- channelName = { activeChannel ?. name ?? "channel" }
513- hasActiveEdit = { threadEditTarget !== null }
514- key = { THREAD_SURFACE_KEY }
515- onClose = { onCloseThread }
516- >
517- { panel }
518- </ FocusThreadDrawer >
519- ) : (
520- wrapAux ( panel , "message-thread-panel" , { key : THREAD_SURFACE_KEY } )
521- ) ;
524+ const wrapThreadPanel = ( panel : React . ReactNode ) => (
525+ < ThreadPanelSurface
526+ channelName = { activeChannel ?. name ?? "channel" }
527+ covered = { threadSurface . covered }
528+ hasActiveEdit = { threadEditTarget !== null }
529+ isFocusDrawer = { useFocusThreadDrawer }
530+ key = { THREAD_SURFACE_KEY }
531+ onClose = { onCloseThread }
532+ ref = { threadSurface . ref }
533+ >
534+ { useFocusThreadDrawer ? panel : wrapAux ( panel , "message-thread-panel" ) }
535+ </ ThreadPanelSurface >
536+ ) ;
522537 const wrapIdlePanel = ( panel : React . ReactNode ) =>
523538 useFocusIdleDrawer && onCloseIdleAuxiliaryPanel ? (
524539 < FocusThreadDrawer
525540 channelName = { activeChannel ?. name ?? "channel" }
526541 key = "idle-auxiliary-surface"
527542 label = { idleAuxiliaryTitle || "Panel" }
528543 onClose = { onCloseIdleAuxiliaryPanel }
544+ restoreFocusTarget = { threadSurface . restoreFocusTarget }
529545 >
530546 { panel }
531547 </ FocusThreadDrawer >
@@ -779,10 +795,8 @@ export const ChannelPane = React.memo(function ChannelPane({
779795 }
780796 showTopBorder = { false }
781797 />
782- { /* The activity accessory is anchored in the dock's reserved
783- bottom rail, so fading it cannot change the observed
784- overlay height or move the conversation. Its natural
785- content height remains responsive. */ }
798+ { /* The reserved bottom rail keeps accessory fades from moving
799+ the conversation while content remains responsive. */ }
786800 < ChannelComposerActivityAccessory
787801 agents = { activityAgents }
788802 channel = { activeChannel }
@@ -821,7 +835,7 @@ export const ChannelPane = React.memo(function ChannelPane({
821835 useSplitAuxiliaryPane = { useSplitAuxiliaryPane }
822836 transparentChrome = { hasSplitAuxiliaryPane }
823837 />
824- ) : priorityIdleAuxiliary && idleAuxiliarySurface ? (
838+ ) : replaceThreadWithIdleAuxiliary && idleAuxiliarySurface ? (
825839 idleAuxiliarySurface
826840 ) : threadHeadMessage ? (
827841 ( ( ) => {
@@ -977,6 +991,9 @@ export const ChannelPane = React.memo(function ChannelPane({
977991 idleAuxiliarySurface
978992 ) }
979993 </ AnimatePresence >
994+ < AnimatePresence onExitComplete = { threadSurface . markExitComplete } >
995+ { showIdleAuxiliaryOverThread ? idleAuxiliarySurface : null }
996+ </ AnimatePresence >
980997 </ div >
981998 ) ;
982999} ) ;
0 commit comments