11import type { TreeNode } from "@components/ui/sidebar/Types" ;
22import { useTasks } from "@features/tasks/hooks/useTasks" ;
3+ import type { ActiveFilters } from "@features/tasks/stores/taskStore" ;
34import {
45 CheckCircleIcon ,
56 CircleIcon ,
@@ -16,6 +17,8 @@ import type { TabState, Task } from "@shared/types";
1617interface UseSidebarMenuDataProps {
1718 userName : string ;
1819 activeTab : TabState | undefined ;
20+ isLoading : boolean ;
21+ activeFilters : ActiveFilters ;
1922 onNavigate : (
2023 type : "task-list" | "recordings" | "notetaker" | "settings" ,
2124 title : string ,
@@ -24,6 +27,7 @@ interface UseSidebarMenuDataProps {
2427 onCreateTask : ( ) => void ;
2528 onStartRecording : ( ) => void ;
2629 onStopRecording : ( ) => void ;
30+ onProjectClick : ( repository : string ) => void ;
2731}
2832
2933function getStatusIcon ( status ?: string ) {
@@ -52,9 +56,12 @@ function getStatusIcon(status?: string) {
5256export function useSidebarMenuData ( {
5357 userName,
5458 activeTab,
59+ isLoading,
60+ activeFilters,
5561 onNavigate,
5662 onTaskClick,
5763 onCreateTask,
64+ onProjectClick,
5865} : UseSidebarMenuDataProps ) : TreeNode {
5966 const { data : allTasks = [ ] } = useTasks ( ) ;
6067 const relevantTasks = allTasks
@@ -64,6 +71,24 @@ export function useSidebarMenuData({
6471 )
6572 . slice ( 0 , 10 ) ;
6673
74+ const repositoryMap = new Map < string , { fullPath : string ; name : string } > ( ) ;
75+ for ( const task of allTasks ) {
76+ const { organization, repository } = task . repository_config || { } ;
77+ if ( organization && repository ) {
78+ const fullPath = `${ organization } /${ repository } ` ;
79+ repositoryMap . set ( fullPath , { fullPath, name : repository } ) ;
80+ }
81+ }
82+
83+ const repositories = Array . from ( repositoryMap . values ( ) ) . sort ( ( a , b ) =>
84+ a . name . localeCompare ( b . name ) ,
85+ ) ;
86+ const activeRepositoryFilters = activeFilters . repository || [ ] ;
87+ const activeRepositoryValue =
88+ activeRepositoryFilters . length === 1
89+ ? activeRepositoryFilters [ 0 ] . value
90+ : null ;
91+
6792 return {
6893 label : userName ,
6994 children : [
@@ -138,11 +163,17 @@ export function useSidebarMenuData({
138163 {
139164 label : "Projects" ,
140165 icon : < FolderIcon size = { 12 } /> ,
141- children : [
142- { label : "Array" } ,
143- { label : "posthog" } ,
144- { label : "agent" } ,
145- ] ,
166+ children : isLoading
167+ ? [ { label : "Loading..." } ]
168+ : repositories . length > 0
169+ ? repositories . map (
170+ ( repo ) : TreeNode => ( {
171+ label : repo . name ,
172+ action : ( ) => onProjectClick ( repo . fullPath ) ,
173+ isActive : activeRepositoryValue === repo . fullPath ,
174+ } ) ,
175+ )
176+ : [ { label : "No projects found" } ] ,
146177 } ,
147178 ] ,
148179 } ;
0 commit comments