| 107 | if (project) { |
| 108 | setLocalProject(project); |
| 109 | // 如果成功加载项目,将状态设置为已完成 |
| 110 | if (project.projectPath) { |
| 111 | setProjectCompleted(true); |
| 112 | isProjectLoadedRef.current = true; |
| 113 | } |
| 114 | } |
| 115 | } catch (error) { |
| 116 | logger.error('Failed to load project from chat:', error); |
| 117 | } finally { |
| 118 | setIsLoading(false); |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | loadProjectFromChat(); |
| 123 | } else { |
| 124 | setIsLoading(projectLoading); |
| 125 | } |
| 126 | }, [chatId, localProject, projectLoading, pollChatProject, projectCompleted]); |
| 127 | |
| 128 | // Use either curProject from context or locally polled project |
| 129 | // This chat's own project wins over the globally selected one. |
| 130 | const activeProject = localProject || curProject; |
| 131 | |
| 132 | // Update projectPathRef when project changes |
| 133 | useEffect(() => { |
| 134 | if (activeProject?.projectPath) { |
| 135 | projectPathRef.current = activeProject.projectPath; |