import { useQuery } from '@tanstack/react-query'; import { FolderGit2Icon, LockIcon } from 'lucide-react'; import { Badge } from '#/components/atoms/badge.jsx'; import { Notice } from '#/components/atoms/notice.jsx'; import { RowIcon } from '#/components/atoms/row-icon.jsx'; import { EmptyState } from '#/components/molecules/empty-state.jsx'; import { ListRow } from '#/components/molecules/list-row.jsx'; import { xrpcGet } from '#/lib/api.js'; import { bytes, timeAgo } from '#/lib/format.js'; import { queryKeys } from '#/lib/query.js'; import { NewRepoDialog } from '#/pages/git-new-repo.jsx'; /** One line summarizing a repository's shape. */ function repoSummary(repo) { if (repo.branches === 0 && repo.bundles === 0) return 'nothing pushed yet'; const parts = [ `${repo.branches} ${repo.branches === 1 ? 'branch' : 'branches'}`, ]; if (repo.tags > 0) { parts.push(`${repo.tags} ${repo.tags === 1 ? 'tag' : 'tags'}`); } parts.push(bytes(repo.size)); if (repo.updatedAt) parts.push(`pushed ${timeAgo(repo.updatedAt)}`); return parts.join(' ยท '); } /** The repository page URL, carrying the space for a private repository. */ export function repoHref(repo) { const base = `/account/git/${encodeURIComponent(repo.name)}`; return repo.space ? `${base}?space=${encodeURIComponent(repo.space)}` : base; } /** * @param {{data: Object, onNavigate: (href: string) => void}} props */ export function GitPage({ data: account, onNavigate }) { const { data, error } = useQuery({ queryKey: queryKeys.gitRepos, queryFn: () => xrpcGet('dev.pdsjs.git.listRepos'), }); if (error) { return {error.message}; } if (!data) return null; const newRepo = ; if (!data.repos.length) { return (
{newRepo}
} title="No repositories yet" description={ <> Your account can host git repositories. Install the helper with{' '} npm install -g @pdsjs/git {' '} and push to{' '} atproto://your.handle/repo-name . History is stored in your repo as bundles, so it rides along in backups and migrates with your account. } />
); } return (
{newRepo}
{data.repos.map((repo) => ( } title={
{repo.name} {repo.space && ( Private )} {repo.defaultBranch && ( {repo.defaultBranch} )}
} description={repo.description || repoSummary(repo)} actions={ repo.description ? ( {repoSummary(repo)} ) : undefined } href={repoHref(repo)} onNavigate={onNavigate} /> ))}
); }