Skip to content

Commit 5983784

Browse files
committed
feat(frontend): add pagination for mobile fellowship section
1 parent 38de70c commit 5983784

File tree

4 files changed

+89
-12
lines changed

4 files changed

+89
-12
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import clsx from "clsx";
2+
3+
interface IMobilePagination {
4+
currentPage: number;
5+
numPages: number;
6+
callback: (newPage: number) => void;
7+
className?: string;
8+
}
9+
10+
const Pagination: React.FC<IMobilePagination> = ({
11+
currentPage,
12+
numPages,
13+
callback,
14+
className,
15+
}) => {
16+
return (
17+
<div
18+
className={clsx(
19+
"flex w-full items-center justify-center gap-8",
20+
className,
21+
)}
22+
>
23+
<button
24+
className={clsx(
25+
"rounded-full bg-primary-blue px-2 text-lg font-bold",
26+
"text-background-2 disabled:bg-stroke",
27+
)}
28+
disabled={currentPage === 1}
29+
aria-label="Move to the previous page"
30+
onClick={() => callback(currentPage - 1)}
31+
>
32+
{"<"}
33+
</button>
34+
<label className="w-12 text-center">
35+
{currentPage}/{numPages}
36+
</label>
37+
<button
38+
className={clsx(
39+
"rounded-full bg-primary-blue px-2 text-lg font-bold",
40+
"text-background-2 disabled:bg-stroke",
41+
)}
42+
disabled={currentPage === numPages}
43+
aria-label="Move to the previous page"
44+
onClick={() => callback(currentPage + 1)}
45+
>
46+
{">"}
47+
</button>
48+
</div>
49+
);
50+
};
51+
52+
export default Pagination;

frontend/src/components/ResearchDevelopment/TabSection/FellowshipTabContent/Fellows/FellowCard.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ const FellowCard: React.FC<Fellow> = ({
3535
<p className="mb-8 mt-6 text-lg text-primary-text lg:mb-12 lg:text-xl">
3636
{workText}
3737
</p>
38-
<div className="mt-auto w-full">
39-
<Divider />
40-
<ExternalLink text={arrowLinkText} url={reportUrl} className="mt-6" />
41-
</div>
38+
{reportUrl ? (
39+
<div className="mt-auto w-full">
40+
<Divider />
41+
<ExternalLink text={arrowLinkText} url={reportUrl} className="mt-6" />
42+
</div>
43+
) : null}
4244
</div>
4345
);
4446
};

frontend/src/components/ResearchDevelopment/TabSection/FellowshipTabContent/Fellows/index.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
2-
import { useMemo, useState } from "react";
2+
import { useMemo, useState, useEffect } from "react";
33

4+
import MobilePagination from "@/components/MobilePagination";
45
import Pagination from "@/components/Pagination";
56
import { useScreenSize } from "@/hooks/useScreenSize";
67
import { Fellow } from "@/queries/research-development/tabs-data";
@@ -26,19 +27,41 @@ const Fellows: React.FC<{ fellows: Fellow[] }> = ({ fellows }) => {
2627
[itemsPerPage, fellows, page],
2728
);
2829

30+
const numPages = useMemo(
31+
() => Math.ceil(fellows.length / itemsPerPage),
32+
[fellows, itemsPerPage],
33+
);
34+
35+
useEffect(() => {
36+
if (itemsPerPage === 1) {
37+
setPage(page * 2 - 1);
38+
} else {
39+
setPage(Math.min(Math.floor(page / 2) + 1, numPages));
40+
}
41+
}, [itemsPerPage]);
42+
2943
return (
3044
<div>
3145
<div className="mb-12 grid grid-cols-1 gap-4 lg:grid-cols-2">
3246
{items.map((fellow) => (
3347
<FellowCard key={fellow.name} {...fellow} />
3448
))}
3549
</div>
36-
<Pagination
37-
currentPage={page}
38-
numPages={Math.ceil(fellows.length / itemsPerPage)}
39-
callback={(val) => setPage(val)}
40-
className="w-full justify-center"
41-
/>
50+
{screenSize === "lg" ? (
51+
<Pagination
52+
currentPage={page}
53+
numPages={numPages}
54+
callback={(val) => setPage(val)}
55+
className="w-full justify-center"
56+
/>
57+
) : (
58+
<MobilePagination
59+
currentPage={page}
60+
numPages={numPages}
61+
callback={(val) => setPage(val)}
62+
className="w-full justify-center"
63+
/>
64+
)}
4265
</div>
4366
);
4467
};

frontend/src/queries/research-development/tabs-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const tabSectionQuery = gql`
9292
}
9393
}
9494
95-
fellows {
95+
fellows(sort: "createdAt:desc") {
9696
name
9797
profession
9898
workText

0 commit comments

Comments
 (0)