|
| 1 | +/** |
| 2 | + * Searchable, grouped repo list used by both RepoSelector (sidebar) |
| 3 | + * and AddWorkflowModal. |
| 4 | + */ |
| 5 | + |
| 6 | +import { useState } from 'react' |
| 7 | +import { IconGitBranch, IconCloud } from '@tabler/icons-react' |
| 8 | +import type { ApiRepo, RepoGroup } from '../hooks/useRepos' |
| 9 | + |
| 10 | +interface Props { |
| 11 | + groups: RepoGroup[] |
| 12 | + /** Currently selected repo id (highlighted with accent border). */ |
| 13 | + selectedId?: string |
| 14 | + onSelect: (repo: ApiRepo) => void |
| 15 | + /** Repo currently being cloned (shows pulsing badge). */ |
| 16 | + cloningId?: string | null |
| 17 | + /** Max height for the scrollable list. */ |
| 18 | + maxHeight?: string |
| 19 | + autoFocus?: boolean |
| 20 | +} |
| 21 | + |
| 22 | +export function RepoList({ groups, selectedId, onSelect, cloningId, maxHeight = '240px', autoFocus }: Props) { |
| 23 | + const [search, setSearch] = useState('') |
| 24 | + |
| 25 | + const filteredGroups = search.trim() |
| 26 | + ? groups.map(g => ({ |
| 27 | + ...g, |
| 28 | + repos: g.repos.filter(r => |
| 29 | + r.name.toLowerCase().includes(search.toLowerCase()) || |
| 30 | + r.description?.toLowerCase().includes(search.toLowerCase()) |
| 31 | + ), |
| 32 | + })).filter(g => g.repos.length > 0) |
| 33 | + : groups |
| 34 | + |
| 35 | + const totalRepos = groups.reduce((n, g) => n + g.repos.length, 0) |
| 36 | + |
| 37 | + if (totalRepos === 0) { |
| 38 | + return <p className="text-center text-[15px] text-neutral-6 py-2">No repositories available</p> |
| 39 | + } |
| 40 | + |
| 41 | + return ( |
| 42 | + <> |
| 43 | + <input |
| 44 | + type="text" |
| 45 | + value={search} |
| 46 | + onChange={e => setSearch(e.target.value)} |
| 47 | + placeholder="Search repos…" |
| 48 | + className="mb-2 w-full rounded-lg border border-neutral-7 bg-neutral-11/50 px-3 py-2 text-[15px] text-neutral-2 placeholder-neutral-5 focus:border-accent-6 focus:outline-none" |
| 49 | + autoFocus={autoFocus} |
| 50 | + /> |
| 51 | + <div className="overflow-y-auto rounded-lg border border-neutral-7 bg-neutral-11/50" style={{ maxHeight }}> |
| 52 | + {filteredGroups.length === 0 ? ( |
| 53 | + <p className="px-3 py-3 text-[13px] text-neutral-5 text-center">No matching repos</p> |
| 54 | + ) : ( |
| 55 | + filteredGroups.map((group) => ( |
| 56 | + <div key={group.owner}> |
| 57 | + <div className="sticky top-0 z-10 bg-neutral-8 backdrop-blur-sm px-3 py-1.5 text-[13px] font-medium uppercase tracking-wider text-neutral-4 border-b border-neutral-7"> |
| 58 | + {group.owner} |
| 59 | + </div> |
| 60 | + {group.repos.map((repo) => { |
| 61 | + const isCloning = cloningId === repo.id |
| 62 | + const isSelected = selectedId === repo.id |
| 63 | + return ( |
| 64 | + <button |
| 65 | + key={repo.id} |
| 66 | + type="button" |
| 67 | + onClick={() => onSelect(repo)} |
| 68 | + disabled={!!cloningId} |
| 69 | + className={`group flex w-full items-start gap-3 border-b border-neutral-7/50 px-3 py-2.5 text-left transition last:border-b-0 ${ |
| 70 | + isSelected |
| 71 | + ? 'bg-accent-9/20 border-l-2 border-l-accent-6' |
| 72 | + : cloningId ? 'cursor-wait opacity-60' : 'hover:bg-neutral-7/20' |
| 73 | + }`} |
| 74 | + > |
| 75 | + <div className="mt-0.5 flex-shrink-0 text-neutral-4 group-hover:text-neutral-3 transition-colors"> |
| 76 | + {repo.cloned ? ( |
| 77 | + <IconGitBranch size={16} stroke={1.5} /> |
| 78 | + ) : ( |
| 79 | + <IconCloud size={16} stroke={1.5} /> |
| 80 | + )} |
| 81 | + </div> |
| 82 | + <div className="min-w-0 flex-1"> |
| 83 | + <div className="flex items-center gap-2"> |
| 84 | + <span className="text-[15px] font-medium text-neutral-2 group-hover:text-neutral-1 transition-colors truncate"> |
| 85 | + {repo.name} |
| 86 | + </span> |
| 87 | + {isCloning && ( |
| 88 | + <span className="flex-shrink-0 rounded bg-primary-9/30 px-1.5 py-0.5 text-[13px] text-primary-4 animate-pulse"> |
| 89 | + cloning... |
| 90 | + </span> |
| 91 | + )} |
| 92 | + {!repo.cloned && !isCloning && ( |
| 93 | + <span className="flex-shrink-0 rounded border border-neutral-6 bg-neutral-8/50 px-1.5 py-0.5 text-[13px] text-neutral-3"> |
| 94 | + remote |
| 95 | + </span> |
| 96 | + )} |
| 97 | + </div> |
| 98 | + {repo.description && ( |
| 99 | + <div className="mt-0.5 text-[13px] text-neutral-6 truncate"> |
| 100 | + {repo.description} |
| 101 | + </div> |
| 102 | + )} |
| 103 | + </div> |
| 104 | + </button> |
| 105 | + ) |
| 106 | + })} |
| 107 | + </div> |
| 108 | + )) |
| 109 | + )} |
| 110 | + </div> |
| 111 | + </> |
| 112 | + ) |
| 113 | +} |
0 commit comments