Skip to content

Commit 48f8c15

Browse files
committed
loading/listing first page of projects
1 parent 920b943 commit 48f8c15

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { useQuery } from "@tanstack/react-query";
8+
import { useCurrentOrg } from "../organizations/orgs-query";
9+
import { projectsService } from "../../service/public-api";
10+
11+
type ListProjectsQueryArgs = {
12+
page: number;
13+
pageSize: number;
14+
};
15+
16+
export const useListProjectsQuery = ({ page, pageSize }: ListProjectsQueryArgs) => {
17+
const { data: org } = useCurrentOrg();
18+
19+
return useQuery(
20+
getListProjectsQueryKey(org?.id || "", { page, pageSize }),
21+
async () => {
22+
if (!org) {
23+
throw new Error("No org currently selected");
24+
}
25+
26+
return projectsService.listProjects({ teamId: org.id, pagination: { page, pageSize } });
27+
},
28+
{
29+
enabled: !!org,
30+
},
31+
);
32+
};
33+
34+
export const getListProjectsQueryKey = (orgId: string, { page, pageSize }: ListProjectsQueryArgs) => {
35+
return ["projects", "list", { orgId, page, pageSize }];
36+
};

components/dashboard/src/repositories/list/RepositoryList.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,25 @@
66

77
import { FC } from "react";
88
import Header from "../../components/Header";
9+
import { useListProjectsQuery } from "../../data/projects/list-projects-query";
10+
import { Loader2 } from "lucide-react";
11+
import { Link } from "react-router-dom";
912

1013
const RepositoryListPage: FC = () => {
14+
const { data, isLoading } = useListProjectsQuery({ page: 1, pageSize: 10 });
15+
1116
return (
1217
<>
1318
<Header title="Repositories" subtitle="" />
19+
20+
{isLoading && <Loader2 className="animate-spin" />}
21+
{!isLoading &&
22+
data?.projects.map((project) => (
23+
<div key={project.id}>
24+
<span>{project.name}</span>
25+
<Link to={`/repositories/${project.id}`}>View</Link>
26+
</div>
27+
))}
1428
</>
1529
);
1630
};

0 commit comments

Comments
 (0)