Skip to content

Commit 3b856d7

Browse files
try using client component
1 parent fa48ae7 commit 3b856d7

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

src/app/api/(client)/client.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use client';
2-
3-
import { FileSourceResponse, fileSourceResponseSchema, SearchRequest, SearchResponse, searchResponseSchema } from "@/lib/schemas";
1+
import { FileSourceResponse, fileSourceResponseSchema, ListRepositoriesResponse, listRepositoriesResponseSchema, SearchRequest, SearchResponse, searchResponseSchema } from "@/lib/schemas";
42

53
export const search = async (body: SearchRequest): Promise<SearchResponse> => {
64
const result = await fetch(`/api/search`, {
@@ -27,4 +25,15 @@ export const fetchFileSource = async (fileName: string, repository: string): Pro
2725
}).then(response => response.json());
2826

2927
return fileSourceResponseSchema.parse(result);
30-
}
28+
}
29+
30+
export const getRepos = async (): Promise<ListRepositoriesResponse> => {
31+
const result = await fetch('/api/repos', {
32+
method: "GET",
33+
headers: {
34+
"Content-Type": "application/json",
35+
},
36+
}).then(response => response.json());
37+
38+
return listRepositoriesResponseSchema.parse(result);
39+
}

src/app/repos/page.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import { Suspense } from "react";
1+
'use client';
2+
23
import { NavigationMenu } from "../navigationMenu";
34
import { RepositoryTable } from "./repositoryTable";
45

5-
export const dynamic = 'force-dynamic'
6-
7-
export default async function ReposPage() {
6+
export default function ReposPage() {
87
return (
98
<div className="h-screen flex flex-col items-center">
109
<NavigationMenu />
11-
<Suspense fallback={<div>Loading...</div>}>
12-
<RepositoryTable />
13-
</Suspense>
10+
<RepositoryTable />
1411
</div>
1512
)
1613
}

src/app/repos/repositoryTable.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
'use server';
1+
'use client';
22

33
import { DataTable } from "@/components/ui/data-table";
44
import { columns, RepositoryColumnInfo } from "./columns";
5-
import { listRepositories } from "@/lib/server/searchService";
65
import { 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

Comments
 (0)