11import * as React from "react" ;
22import { Bot , Hash , LogIn , Plus , Sparkles , UserPlus } from "lucide-react" ;
3+ import { useAppNavigation } from "@/app/navigation/useAppNavigation" ;
34import { useMediaUpload } from "@/features/messages/lib/useMediaUpload" ;
45import { MessageComposer } from "@/features/messages/ui/MessageComposer" ;
56import { DropZoneOverlay } from "@/features/messages/ui/ComposerAttachments" ;
@@ -61,6 +62,8 @@ export const ChannelPane = React.memo(function ChannelPane({
6162 agentPubkeysPending = false ,
6263 agentSessionAgents,
6364 activityAgents = agentSessionAgents ,
65+ autoSendDraftKey = null ,
66+ onAutoSendComplete = null ,
6467 botTypingEntries,
6568 channelFind,
6669 channelManagementOpen = false ,
@@ -148,6 +151,7 @@ export const ChannelPane = React.memo(function ChannelPane({
148151 const welcomeComposerHideTimerRef = React . useRef < number | null > ( null ) ;
149152 const [ welcomeComposerBannerState , setWelcomeComposerBannerState ] =
150153 React . useState < WelcomeComposerBannerState > ( "prompt" ) ;
154+ const { goChannel } = useAppNavigation ( ) ;
151155 const mainComposerMedia = useMediaUpload ( ) ;
152156 const isNonMemberView =
153157 activeChannel !== null &&
@@ -156,6 +160,20 @@ export const ChannelPane = React.memo(function ChannelPane({
156160 ! activeChannel . archivedAt ;
157161 const hasMainComposerOverlay = ! isNonMemberView ;
158162 const activeChannelId = activeChannel ?. id ?? null ;
163+ // Clear the ?autoSend search param once the auto-submit fires so
164+ // back-navigation cannot re-trigger the send.
165+ // When `onAutoSendComplete` is provided it does a surgical single-key clear
166+ // that preserves `?thread` and all other panel search state (required for
167+ // the thread-draft send path so the thread panel does not unmount before the
168+ // deferred setTimeout(0) submit fires). The goChannel fallback is kept for
169+ // callers that do not supply the prop (e.g. isolated tests / older wrappers).
170+ const handleAutoSubmitComplete = React . useCallback ( ( ) => {
171+ if ( onAutoSendComplete ) {
172+ onAutoSendComplete ( ) ;
173+ } else if ( activeChannelId ) {
174+ void goChannel ( activeChannelId , { replace : true } ) ;
175+ }
176+ } , [ activeChannelId , goChannel , onAutoSendComplete ] ) ;
159177 const huddleMemberPubkeys = React . useMemo (
160178 ( ) => getDmHuddleMemberPubkeys ( activeChannel , agentPubkeys , currentPubkey ) ,
161179 [ activeChannel , agentPubkeys , currentPubkey ] ,
@@ -668,6 +686,8 @@ export const ChannelPane = React.memo(function ChannelPane({
668686 containerClassName = "px-5"
669687 disabled = { isComposerDisabled }
670688 editTarget = { mainEditTarget }
689+ autoSubmitDraftKey = { autoSendDraftKey }
690+ onAutoSubmitComplete = { handleAutoSubmitComplete }
671691 isSending = { isSending }
672692 mediaController = { mainComposerMedia }
673693 onCancelEdit = { onCancelEdit }
@@ -760,6 +780,8 @@ export const ChannelPane = React.memo(function ChannelPane({
760780 }
761781 layout = { useSplitAuxiliaryPane ? "split" : "standalone" }
762782 transparentChrome = { useSplitAuxiliaryPane }
783+ autoSendDraftKey = { autoSendDraftKey }
784+ onAutoSubmitComplete = { handleAutoSubmitComplete }
763785 onCancelEdit = { onCancelEdit }
764786 onCancelReply = { onCancelThreadReply }
765787 onClose = { onCloseThread }
0 commit comments