1+ import { usePullRequestDraftThread } from "./chat/usePullRequestDraftThread" ;
12import { useComposerSelection } from "./chat/useComposerSelection" ;
23import { useProjectCloneBanner } from "./chat/useProjectCloneBanner" ;
34import { useAttachmentPreviewHandoff } from "./chat/useAttachmentPreviewHandoff" ;
@@ -183,7 +184,7 @@ import { cn } from "~/lib/utils";
183184import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar" ;
184185import { stackedThreadToast , toastManager } from "./ui/toast" ;
185186import { projectScriptIdFromCommand } from "~/projectScripts" ;
186- import { newDraftId , newMessageId , newThreadId } from "~/lib/utils" ;
187+ import { newMessageId } from "~/lib/utils" ;
187188import { registerFaviconProjectForThread } from "~/browserFaviconStore" ;
188189import {
189190 applyProviderInstanceSettings ,
@@ -207,7 +208,6 @@ import {
207208 deriveLogicalProjectKeyFromSettings ,
208209 selectProjectGroupingSettings ,
209210} from "../logicalProject" ;
210- import { buildDraftThreadRouteParams } from "../threadRoutes" ;
211211import {
212212 isSameSidebarThreadRef ,
213213 useSidebarPendingFileDropStore ,
@@ -259,7 +259,6 @@ import {
259259 BranchRestoreConfirmHost ,
260260 DeviceSetupDialogHost ,
261261 openBranchRestoreConfirm ,
262- openPullRequestThreadDialog ,
263262 PullRequestThreadDialogHost ,
264263 RevertConfirmHost ,
265264} from "./chat/ChatOverlayHosts" ;
@@ -635,13 +634,6 @@ export default function ChatView(props: ChatViewProps) {
635634 } ) ;
636635 const setComposerDraftPrompt = useComposerDraftStore ( ( store ) => store . setPrompt ) ;
637636 const setDraftThreadContext = useComposerDraftStore ( ( store ) => store . setDraftThreadContext ) ;
638- const getDraftSessionByLogicalProjectKey = useComposerDraftStore (
639- ( store ) => store . getDraftSessionByLogicalProjectKey ,
640- ) ;
641- const getDraftSession = useComposerDraftStore ( ( store ) => store . getDraftSession ) ;
642- const setLogicalProjectDraftThreadId = useComposerDraftStore (
643- ( store ) => store . setLogicalProjectDraftThreadId ,
644- ) ;
645637 const composerImagesRef = useRef < ComposerImageAttachment [ ] > ( [ ] ) ;
646638 const composerFilesRef = useRef < ComposerFileAttachment [ ] > ( [ ] ) ;
647639 const composerTerminalContextsRef = useRef < TerminalContextDraft [ ] > ( [ ] ) ;
@@ -1198,91 +1190,18 @@ export default function ChatView(props: ChatViewProps) {
11981190 activeEnvironment : activeEnvironmentOption ,
11991191 canPickEnvironment : hasMultipleEnvironments ,
12001192 } ) ;
1201- const openPullRequestDialog = ( reference ?: string ) => {
1202- if ( ! canCheckoutPullRequestIntoThread ) {
1203- return ;
1204- }
1205- if ( activeThreadKey === null ) return ;
1206- openPullRequestThreadDialog ( activeThreadKey , reference ) ;
1207- } ;
1208- const openPullRequestDialogStable = useStableCallback ( openPullRequestDialog ) ;
12091193
1210- const openOrReuseProjectDraftThread = async ( input : {
1211- branch : string ;
1212- worktreePath : string | null ;
1213- envMode : DraftThreadEnvMode ;
1214- } ) => {
1215- if ( ! activeProject ) {
1216- throw new Error ( "No active project is available for this pull request." ) ;
1217- }
1218- const activeProjectRef = scopeProjectRef ( activeProject . environmentId , activeProject . id ) ;
1219- const logicalProjectKey = deriveLogicalProjectKeyFromSettings (
1220- activeProject ,
1194+ const { handlePreparedPullRequestThreadStable, openPullRequestDialogStable } =
1195+ usePullRequestDraftThread ( {
1196+ routeKind,
1197+ draftId,
1198+ settings,
12211199 projectGroupingSettings,
1222- ) ;
1223- const storedDraftSession = getDraftSessionByLogicalProjectKey ( logicalProjectKey ) ;
1224- if ( storedDraftSession ) {
1225- setDraftThreadContext ( storedDraftSession . draftId , input ) ;
1226- setLogicalProjectDraftThreadId (
1227- logicalProjectKey ,
1228- activeProjectRef ,
1229- storedDraftSession . draftId ,
1230- {
1231- threadId : storedDraftSession . threadId ,
1232- ...input ,
1233- } ,
1234- ) ;
1235- if ( routeKind !== "draft" || draftId !== storedDraftSession . draftId ) {
1236- await navigate ( {
1237- to : "/draft/$draftId" ,
1238- params : buildDraftThreadRouteParams ( storedDraftSession . draftId ) ,
1239- } ) ;
1240- }
1241- return storedDraftSession . threadId ;
1242- }
1243-
1244- const activeDraftSession = routeKind === "draft" && draftId ? getDraftSession ( draftId ) : null ;
1245- if ( ! isServerThread && activeDraftSession ?. logicalProjectKey === logicalProjectKey && draftId ) {
1246- setDraftThreadContext ( draftId , input ) ;
1247- setLogicalProjectDraftThreadId ( logicalProjectKey , activeProjectRef , draftId , {
1248- threadId : activeDraftSession . threadId ,
1249- createdAt : activeDraftSession . createdAt ,
1250- runtimeMode : activeDraftSession . runtimeMode ,
1251- interactionMode : activeDraftSession . interactionMode ,
1252- ...input ,
1253- } ) ;
1254- return activeDraftSession . threadId ;
1255- }
1256-
1257- const nextDraftId = newDraftId ( ) ;
1258- const nextThreadId = newThreadId ( ) ;
1259- setLogicalProjectDraftThreadId ( logicalProjectKey , activeProjectRef , nextDraftId , {
1260- threadId : nextThreadId ,
1261- createdAt : new Date ( ) . toISOString ( ) ,
1262- runtimeMode : resolveProjectSettings ( settings , activeProject . id , activeProject ) . settings
1263- . defaultRuntimeMode ,
1264- interactionMode : DEFAULT_INTERACTION_MODE ,
1265- ...input ,
1266- } ) ;
1267- await navigate ( {
1268- to : "/draft/$draftId" ,
1269- params : buildDraftThreadRouteParams ( nextDraftId ) ,
1270- } ) ;
1271- return nextThreadId ;
1272- } ;
1273-
1274- const handlePreparedPullRequestThread = async ( input : {
1275- branch : string ;
1276- worktreePath : string | null ;
1277- } ) => {
1278- await openOrReuseProjectDraftThread ( {
1279- branch : input . branch ,
1280- worktreePath : input . worktreePath ,
1281- envMode : input . worktreePath ? "worktree" : "local" ,
1200+ activeProject,
1201+ activeThreadKey,
1202+ isServerThread,
1203+ canCheckoutPullRequestIntoThread,
12821204 } ) ;
1283- } ;
1284- const handlePreparedPullRequestThreadStable = useStableCallback ( handlePreparedPullRequestThread ) ;
1285-
12861205 const serverConfig = activeThread
12871206 ? ( activeEnvironment ?. serverConfig ?? null )
12881207 : ( primaryEnvironment ?. serverConfig ?? null ) ;
0 commit comments