@@ -262,6 +262,45 @@ const PlanPage: React.FC = () => {
262262
263263 return ( ) => unsubscribe ( ) ;
264264 } , [ scrollToBottom , planData , processAgentMessage ] ) ; //onPlanReceived, scrollToBottom
265+ // Create loadPlanData function with useCallback to memoize it
266+ const loadPlanData = useCallback (
267+ async ( useCache = true ) : Promise < ProcessedPlanData | null > => {
268+ if ( ! planId ) return null ;
269+
270+ setLoading ( true ) ;
271+ try {
272+
273+ let planResult : ProcessedPlanData | null = null ;
274+ console . log ( "Fetching plan with ID:" , planId ) ;
275+ planResult = await PlanDataService . fetchPlanData ( planId , useCache ) ;
276+ console . log ( "Plan data fetched:" , planResult ) ;
277+ if ( planResult ?. plan ?. overall_status === PlanStatus . IN_PROGRESS ) {
278+ setShowApprovalButtons ( true ) ;
279+
280+ } else {
281+ setShowApprovalButtons ( false ) ;
282+ setWaitingForPlan ( false ) ;
283+ }
284+ if ( planResult ?. plan ?. overall_status !== PlanStatus . COMPLETED ) {
285+ setContinueWithWebsocketFlow ( true ) ;
286+ }
287+ if ( planResult ?. messages ) {
288+ setAgentMessages ( planResult . messages ) ;
289+ }
290+ if ( planResult ?. mplan ) {
291+ setPlanApprovalRequest ( planResult . mplan ) ;
292+ }
293+ setPlanData ( planResult ) ;
294+ return planResult ;
295+ } catch ( err ) {
296+ console . log ( "Failed to load plan data:" , err ) ;
297+ return null ;
298+ } finally {
299+ setLoading ( false ) ;
300+ }
301+ } ,
302+ [ planId , navigate ]
303+ ) ;
265304
266305 // Loading message rotation effect
267306 useEffect ( ( ) => {
@@ -337,47 +376,7 @@ const PlanPage: React.FC = () => {
337376 webSocketService . disconnect ( ) ;
338377 } ;
339378 }
340- } , [ planId , loading ] ) ;
341-
342- // Create loadPlanData function with useCallback to memoize it
343- const loadPlanData = useCallback (
344- async ( useCache = true ) : Promise < ProcessedPlanData | null > => {
345- if ( ! planId ) return null ;
346-
347- setLoading ( true ) ;
348- try {
349-
350- let planResult : ProcessedPlanData | null = null ;
351- console . log ( "Fetching plan with ID:" , planId ) ;
352- planResult = await PlanDataService . fetchPlanData ( planId , useCache ) ;
353- console . log ( "Plan data fetched:" , planResult ) ;
354- if ( planResult ?. plan ?. overall_status === PlanStatus . IN_PROGRESS ) {
355- setShowApprovalButtons ( true ) ;
356-
357- } else {
358- setShowApprovalButtons ( false ) ;
359- setWaitingForPlan ( false ) ;
360- }
361- if ( planResult ?. plan ?. overall_status !== PlanStatus . COMPLETED ) {
362- setContinueWithWebsocketFlow ( true ) ;
363- }
364- if ( planResult ?. messages ) {
365- setAgentMessages ( planResult . messages ) ;
366- }
367- if ( planResult ?. mplan ) {
368- setPlanApprovalRequest ( planResult . mplan ) ;
369- }
370- setPlanData ( planResult ) ;
371- return planResult ;
372- } catch ( err ) {
373- console . log ( "Failed to load plan data:" , err ) ;
374- return null ;
375- } finally {
376- setLoading ( false ) ;
377- }
378- } ,
379- [ planId , navigate ]
380- ) ;
379+ } , [ planId , loading , continueWithWebsocketFlow , loadPlanData , planData ] ) ;
381380
382381
383382 // Handle plan approval
0 commit comments