@@ -75,6 +75,16 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
7575 getFolderIds : ( ) => folder . id ,
7676 } )
7777
78+ // Folder expand hook - must be declared before callbacks that use expandFolder
79+ const {
80+ isExpanded,
81+ handleToggleExpanded,
82+ expandFolder,
83+ handleKeyDown : handleExpandKeyDown ,
84+ } = useFolderExpand ( {
85+ folderId : folder . id ,
86+ } )
87+
7888 /**
7989 * Handle create workflow in folder using React Query mutation.
8090 * Generates name and color upfront for optimistic UI updates.
@@ -95,6 +105,8 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
95105
96106 if ( result . id ) {
97107 router . push ( `/workspace/${ workspaceId } /w/${ result . id } ` )
108+ // Expand the parent folder so the new workflow is visible
109+ expandFolder ( )
98110 // Scroll to the newly created workflow
99111 window . dispatchEvent (
100112 new CustomEvent ( SIDEBAR_SCROLL_EVENT , { detail : { itemId : result . id } } )
@@ -104,7 +116,7 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
104116 // Error already handled by mutation's onError callback
105117 logger . error ( 'Failed to create workflow in folder:' , error )
106118 }
107- } , [ createWorkflowMutation , workspaceId , folder . id , router ] )
119+ } , [ createWorkflowMutation , workspaceId , folder . id , router , expandFolder ] )
108120
109121 /**
110122 * Handle create sub-folder using React Query mutation.
@@ -118,6 +130,8 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
118130 parentId : folder . id ,
119131 } )
120132 if ( result . id ) {
133+ // Expand the parent folder so the new folder is visible
134+ expandFolder ( )
121135 // Scroll to the newly created folder
122136 window . dispatchEvent (
123137 new CustomEvent ( SIDEBAR_SCROLL_EVENT , { detail : { itemId : result . id } } )
@@ -126,16 +140,7 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
126140 } catch ( error ) {
127141 logger . error ( 'Failed to create folder:' , error )
128142 }
129- } , [ createFolderMutation , workspaceId , folder . id ] )
130-
131- // Folder expand hook
132- const {
133- isExpanded,
134- handleToggleExpanded,
135- handleKeyDown : handleExpandKeyDown ,
136- } = useFolderExpand ( {
137- folderId : folder . id ,
138- } )
143+ } , [ createFolderMutation , workspaceId , folder . id , expandFolder ] )
139144
140145 /**
141146 * Drag start handler - sets folder data for drag operation
0 commit comments