|
1 | 1 | import { useParams, Link } from 'react-router-dom'; |
2 | | -import { useEffect } from 'react'; |
| 2 | +import { LogOut } from 'lucide-react'; |
| 3 | +import { useEffect, useState } from 'react'; |
3 | 4 | import { useReposState, getRepos } from '@/store/repositories'; |
4 | | -import { toast } from 'sonner'; |
| 5 | +import { useRepoFilesState, getRepoFiles } from '@/store/repofiles'; |
5 | 6 | import { Repo } from '@/types'; |
| 7 | +import { DataTable } from '@/components/ui/DataTable'; |
| 8 | +import columns from '@/components/views/ColumnDef'; |
| 9 | +import { Input } from '@/components/ui/input'; |
| 10 | +import { useAuth } from '@/context/AuthProvider'; |
| 11 | +import { Button } from '@/components/ui/button'; |
6 | 12 |
|
7 | 13 | export function RepoViewPage() { |
8 | | - const { repoPath } = useParams<{ repoPath: string }>(); |
| 14 | + const { user, repoPath } = useParams<{ user: string; repoPath: string }>(); |
9 | 15 | const repos = useReposState(); |
| 16 | + const repoFiles = useRepoFilesState(); |
| 17 | + const [searchQuery, setSearchQuery] = useState(''); |
| 18 | + const { logout, AuthDisabled } = useAuth(); |
10 | 19 |
|
11 | 20 | useEffect(() => { |
12 | 21 | if (!repoPath) return; |
13 | | - // fetch all repos if not already loaded |
14 | 22 | if (!repos.repos.get().length) { |
15 | 23 | getRepos(''); |
16 | 24 | } |
17 | 25 | }, [repoPath]); |
18 | 26 |
|
19 | | - const repoItem: Repo | any = repos.repos.get().find((r: Repo | any) => r.path === repoPath); |
20 | | - |
21 | | - if (!repoItem) { |
22 | | - return ( |
23 | | - <div className="p-4"> |
24 | | - <h2 className="text-xl font-bold">Repository not found</h2> |
25 | | - <Link to="/resource" className="text-blue-500"> |
26 | | - Back to list |
27 | | - </Link> |
28 | | - </div> |
29 | | - ); |
30 | | - } |
| 27 | + useEffect(() => { |
| 28 | + if (!user || !repoPath) return; |
| 29 | + getRepoFiles(searchQuery, user, repoPath); |
| 30 | + }, [user, searchQuery]); |
31 | 31 |
|
32 | 32 | return ( |
33 | 33 | <div className="flex-grow overflow-auto"> |
34 | | - <div className="flex flex-row py-2 px-2 items-center justify-between"></div> |
| 34 | + <div className="flex flex-row py-2 px-2 items-center justify-between"> |
| 35 | + <Input |
| 36 | + placeholder="Filter by name..." |
| 37 | + className="placeholder:text-muted-foreground flex h-6 w-full rounded-md bg-transparent py-2 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50" |
| 38 | + onChange={(e) => setSearchQuery(e.target.value)} |
| 39 | + /> |
| 40 | + {!AuthDisabled && ( |
| 41 | + <Button onClick={logout} className="ml-2 text-xs"> |
| 42 | + <LogOut size={12} /> |
| 43 | + </Button> |
| 44 | + )} |
| 45 | + </div> |
35 | 46 |
|
36 | 47 | <div className="grid grid-cols-1"> |
37 | | - <div className="p-4"> |
38 | | - <h2 className="text-2xl font-bold mb-4">{repoItem.name}</h2> |
39 | | - <p className="mb-2"> |
40 | | - <strong>Path:</strong> {repoItem.path} |
41 | | - </p> |
42 | | - <p className="mb-2"> |
43 | | - <strong>User:</strong> {repoItem.user?.name} |
44 | | - </p> |
45 | | - <Link to="/resource" className="text-blue-500"> |
46 | | - Back to list |
47 | | - </Link> |
| 48 | + <div className="mx-3"> |
| 49 | + <DataTable |
| 50 | + menuDisabled={true} |
| 51 | + kind="repo" |
| 52 | + noResult={false} |
| 53 | + columns={columns as any} |
| 54 | + data={repoFiles.files.get() as any} |
| 55 | + /> |
48 | 56 | </div> |
49 | 57 | </div> |
50 | 58 | </div> |
|
0 commit comments