()
| 163 | }, [storesSessions]); |
| 164 | |
| 165 | const loadProjectsWithSessions = async () => { |
| 166 | try { |
| 167 | setIsLoading(true); |
| 168 | const response = await API.sessions.getAllWithProjects(); |
| 169 | if (response.success && response.data) { |
| 170 | setProjectsWithSessions(response.data); |
| 171 | |
| 172 | // Auto-expand projects that have sessions |
| 173 | const projectsToExpand = new Set<number>(); |
| 174 | response.data.forEach((project: ProjectWithSessions) => { |
| 175 | if (project.sessions.length > 0) { |
| 176 | projectsToExpand.add(project.id); |
| 177 | } |
| 178 | }); |
| 179 | setExpandedProjects(projectsToExpand); |
| 180 | |
| 181 | // Also expand the project containing the active session |
| 182 | if (activeSessionId) { |
| 183 | response.data.forEach((project: ProjectWithSessions) => { |
| 184 | if (project.sessions.some(s => s.id === activeSessionId)) { |
| 185 | projectsToExpand.add(project.id); |
| 186 | } |
| 187 | }); |
| 188 | } |
| 189 | } |
| 190 | } catch (error) { |
| 191 | console.error('Failed to load projects with sessions:', error); |
| 192 | } finally { |
| 193 | setIsLoading(false); |
| 194 | } |
| 195 | }; |
| 196 | |
| 197 | const toggleProject = (projectId: number) => { |
| 198 | setExpandedProjects(prev => { |
no test coverage detected