@@ -78,6 +78,8 @@ import { useOpenPrLink } from "../lib/openPullRequestLink";
7878import { releaseProjectDraftUploads } from "../lib/composerDraftUploads" ;
7979import { isTerminalFocused } from "../lib/terminalFocus" ;
8080import { isMacPlatform } from "../lib/utils" ;
81+ import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore" ;
82+ import { makeWorkspaceFileDropHandlers } from "./chat/workspaceFileDrop" ;
8183import {
8284 readThreadShell ,
8385 useProjects ,
@@ -326,7 +328,7 @@ interface SidebarThreadRowProps {
326328 threadRef : ScopedThreadRef ,
327329 orderedProjectThreadKeys : readonly string [ ] ,
328330 ) => void ;
329- navigateToThread : ( threadRef : ScopedThreadRef ) => void ;
331+ navigateToThread : ( threadRef : ScopedThreadRef ) => Promise < void > ;
330332 handleMultiSelectContextMenu : ( position : { x : number ; y : number } ) => Promise < void > ;
331333 handleThreadContextMenu : (
332334 threadRef : ScopedThreadRef ,
@@ -345,6 +347,7 @@ interface SidebarThreadRowProps {
345347 prUrl : string ,
346348 threadRef ?: ScopedThreadRef ,
347349 ) => boolean ;
350+ onFileDropThreads : ( threadRef : ScopedThreadRef , files : File [ ] ) => void ;
348351}
349352
350353const SidebarThreadRow = memo ( function SidebarThreadRow ( props : SidebarThreadRowProps ) {
@@ -372,10 +375,28 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
372375 cancelRename,
373376 attemptArchiveThread,
374377 openPrLink,
378+ onFileDropThreads,
375379 thread,
376380 } = props ;
377381 const threadRef = scopeThreadRef ( thread . environmentId , thread . id ) ;
378382 const threadKey = scopedThreadKey ( threadRef ) ;
383+ const [ isFileDragOver , setIsFileDragOver ] = useState ( false ) ;
384+ const fileDropHandlers = useMemo (
385+ ( ) =>
386+ makeWorkspaceFileDropHandlers ( {
387+ setDragActive : setIsFileDragOver ,
388+ addFiles : ( files ) => {
389+ onFileDropThreads ( threadRef , files ) ;
390+ } ,
391+ } ) ,
392+ [ onFileDropThreads , threadRef ] ,
393+ ) ;
394+ useEffect ( ( ) => {
395+ if ( ! isFileDragOver ) return ;
396+ const clearFileDrag = ( ) => setIsFileDragOver ( false ) ;
397+ window . addEventListener ( "dragend" , clearFileDrag ) ;
398+ return ( ) => window . removeEventListener ( "dragend" , clearFileDrag ) ;
399+ } , [ isFileDragOver ] ) ;
379400 const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease ( isActive ) ;
380401 const lastVisitedAt = useUiStateStore ( ( state ) => state . threadLastVisitedAtById [ threadKey ] ) ;
381402 const isSelected = useThreadSelectionStore ( ( state ) => state . selectedThreadKeys . has ( threadKey ) ) ;
@@ -663,6 +684,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
663684 ref = { rowRef }
664685 className = "w-full"
665686 data-thread-item
687+ { ...fileDropHandlers }
666688 onMouseLeave = { handleMouseLeave }
667689 onBlurCapture = { handleBlurCapture }
668690 >
@@ -674,7 +696,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
674696 className = { `${ resolveThreadRowClassName ( {
675697 isActive,
676698 isSelected,
677- } ) } relative isolate`}
699+ } ) } relative isolate${ isFileDragOver ? " ring-1 ring-inset ring-primary/70" : "" } `}
678700 onClick = { handleRowClick }
679701 onDoubleClick = { handleRowDoubleClick }
680702 onKeyDown = { handleRowKeyDown }
@@ -916,7 +938,8 @@ interface SidebarProjectThreadListProps {
916938 threadRef : ScopedThreadRef ,
917939 orderedProjectThreadKeys : readonly string [ ] ,
918940 ) => void ;
919- navigateToThread : ( threadRef : ScopedThreadRef ) => void ;
941+ navigateToThread : ( threadRef : ScopedThreadRef ) => Promise < void > ;
942+ onFileDropThreads : ( threadRef : ScopedThreadRef , files : File [ ] ) => void ;
920943 handleMultiSelectContextMenu : ( position : { x : number ; y : number } ) => Promise < void > ;
921944 handleThreadContextMenu : (
922945 threadRef : ScopedThreadRef ,
@@ -968,6 +991,7 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
968991 attachThreadListAutoAnimateRef,
969992 handleThreadClick,
970993 navigateToThread,
994+ onFileDropThreads,
971995 handleMultiSelectContextMenu,
972996 handleThreadContextMenu,
973997 clearSelection,
@@ -1019,6 +1043,7 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
10191043 confirmArchiveButtonRefs = { confirmArchiveButtonRefs }
10201044 handleThreadClick = { handleThreadClick }
10211045 navigateToThread = { navigateToThread }
1046+ onFileDropThreads = { onFileDropThreads }
10221047 handleMultiSelectContextMenu = { handleMultiSelectContextMenu }
10231048 handleThreadContextMenu = { handleThreadContextMenu }
10241049 clearSelection = { clearSelection }
@@ -1136,6 +1161,8 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
11361161 ( settings ) => settings . sidebarThreadPreviewCount ,
11371162 ) ;
11381163 const router = useRouter ( ) ;
1164+ const queuePendingFileDrop = useSidebarPendingFileDropStore ( ( s ) => s . queuePendingFileDrop ) ;
1165+ const clearPendingFileDrop = useSidebarPendingFileDropStore ( ( s ) => s . clearPendingFileDrop ) ;
11391166 const { isMobile, setOpenMobile } = useSidebar ( ) ;
11401167 const markThreadUnread = useUiStateStore ( ( state ) => state . markThreadUnread ) ;
11411168 const setProjectExpanded = useUiStateStore ( ( state ) => state . setProjectExpanded ) ;
@@ -1740,13 +1767,32 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
17401767 if ( isMobile ) {
17411768 setOpenMobile ( false ) ;
17421769 }
1743- void router . navigate ( {
1770+ return router . navigate ( {
17441771 to : "/$environmentId/$threadId" ,
17451772 params : buildThreadRouteParams ( threadRef ) ,
17461773 } ) ;
17471774 } ,
17481775 [ clearSelection , isMobile , router , setOpenMobile , setSelectionAnchor ] ,
17491776 ) ;
1777+ const handleThreadFileDrop = useCallback (
1778+ async ( threadRef : ScopedThreadRef , files : File [ ] ) => {
1779+ const dropId = queuePendingFileDrop ( { threadRef, files } ) ;
1780+ const targetPathname = router . buildLocation ( {
1781+ to : "/$environmentId/$threadId" ,
1782+ params : buildThreadRouteParams ( threadRef ) ,
1783+ } ) . pathname ;
1784+ if ( targetPathname === router . state . location . pathname ) return ;
1785+ try {
1786+ await navigateToThread ( threadRef ) ;
1787+ if ( targetPathname !== router . state . location . pathname ) {
1788+ clearPendingFileDrop ( dropId ) ;
1789+ }
1790+ } catch {
1791+ clearPendingFileDrop ( dropId ) ;
1792+ }
1793+ } ,
1794+ [ clearPendingFileDrop , navigateToThread , queuePendingFileDrop , router ] ,
1795+ ) ;
17501796
17511797 const handleThreadClick = useCallback (
17521798 (
@@ -2409,6 +2455,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
24092455 attachThreadListAutoAnimateRef = { attachThreadListAutoAnimateRef }
24102456 handleThreadClick = { handleThreadClick }
24112457 navigateToThread = { navigateToThread }
2458+ onFileDropThreads = { handleThreadFileDrop }
24122459 handleMultiSelectContextMenu = { handleMultiSelectContextMenu }
24132460 handleThreadContextMenu = { handleThreadContextMenu }
24142461 clearSelection = { clearSelection }
0 commit comments