1- 'use server ' ;
1+ 'use client ' ;
22
33import { DataTable } from "@/components/ui/data-table" ;
44import { columns , RepositoryColumnInfo } from "./columns" ;
5- import { listRepositories } from "@/lib/server/searchService" ;
65import { isServiceError } from "@/lib/utils" ;
6+ import { useQuery } from "@tanstack/react-query" ;
7+ import { useMemo } from "react" ;
8+ import { getRepos } from "../api/(client)/client" ;
79
8- export const RepositoryTable = async ( ) => {
9- const _repos = await listRepositories ( ) ;
10+ export const RepositoryTable = ( ) => {
11+ const { data : _repos } = useQuery ( {
12+ queryKey : [ "repos" ] ,
13+ queryFn : ( ) => getRepos ( ) ,
14+ } ) ;
15+
16+ const repos = useMemo ( ( ) => {
17+ if ( isServiceError ( _repos ) ) {
18+ return [ ] ;
19+ }
1020
11- if ( isServiceError ( _repos ) ) {
12- return < div > Error fetching repositories</ div > ;
13- }
14- const repos = _repos . List . Repos . map ( ( repo ) : RepositoryColumnInfo => {
15- return {
21+ return _repos ?. List . Repos . map ( ( repo ) : RepositoryColumnInfo => ( {
1622 name : repo . Repository . Name ,
1723 branches : repo . Repository . Branches . map ( ( branch ) => {
1824 return {
@@ -27,10 +33,10 @@ export const RepositoryTable = async () => {
2733 latestCommit : repo . Repository . LatestCommitDate ,
2834 indexedFiles : repo . Stats . Documents ,
2935 commitUrlTemplate : repo . Repository . CommitURLTemplate ,
30- }
31- } ) . sort ( ( a , b ) => {
32- return new Date ( b . lastIndexed ) . getTime ( ) - new Date ( a . lastIndexed ) . getTime ( ) ;
33- } ) ;
36+ } ) ) . sort ( ( a , b ) => {
37+ return new Date ( b . lastIndexed ) . getTime ( ) - new Date ( a . lastIndexed ) . getTime ( ) ;
38+ } ) ?? [ ] ;
39+ } , [ _repos ] ) ;
3440
3541 return (
3642 < DataTable
0 commit comments