|
6 | 6 | Input,
|
7 | 7 | Layout,
|
8 | 8 | message,
|
| 9 | + Pagination, |
| 10 | + PaginationProps, |
9 | 11 | Row,
|
10 | 12 | Select,
|
11 | 13 | Table,
|
@@ -61,6 +63,10 @@ export default function Home() {
|
61 | 63 |
|
62 | 64 | // Table States
|
63 | 65 | const [questions, setQuestions] = useState<Question[] | undefined>(undefined); // Store the questions
|
| 66 | + const [totalCount, setTotalCount] = useState<number | undefined>(undefined); // Store the total count of questions |
| 67 | + const [totalPages, setTotalPages] = useState<number | undefined>(undefined); // Store the total number of pages |
| 68 | + const [currentPage, setCurrentPage] = useState<number | undefined>(undefined); // Store the current page |
| 69 | + const [limit, setLimit] = useState<number | undefined>(10); // Store the quantity of questions to be displayed |
64 | 70 | const [isLoading, setIsLoading] = useState<boolean>(true); // Store the states related to table's loading
|
65 | 71 |
|
66 | 72 | // Filtering States
|
@@ -103,15 +109,16 @@ export default function Home() {
|
103 | 109 | setIsLoading(true);
|
104 | 110 | }
|
105 | 111 |
|
106 |
| - GetQuestions().then((data) => { |
107 |
| - setQuestions(data); |
| 112 | + GetQuestions(currentPage, limit).then((data) => { |
| 113 | + setQuestions(data.questions); |
| 114 | + setTotalCount(data.totalCount); |
| 115 | + setTotalPages(data.totalPages); |
| 116 | + setCurrentPage(data.currentPage); |
| 117 | + setLimit(data.limit); |
108 | 118 | setIsLoading(false);
|
109 | 119 | });
|
110 |
| - }; |
111 |
| - // Include States for Create/Edit Modal (TODO: Sean) |
112 |
| - |
113 |
| - // When the page is initialised, fetch all the questions ONCE and display in table |
114 |
| - useEffect(loadQuestions, []); |
| 120 | + } |
| 121 | + useEffect(loadQuestions, [limit, currentPage]); |
115 | 122 |
|
116 | 123 | // Table column specification
|
117 | 124 | const columns: TableProps<Question>["columns"] = [
|
@@ -154,7 +161,7 @@ export default function Home() {
|
154 | 161 | title: "Actions",
|
155 | 162 | key: "actions",
|
156 | 163 | dataIndex: "id",
|
157 |
| - render: (id: string) => ( |
| 164 | + render: (id: number) => ( |
158 | 165 | <div>
|
159 | 166 | {/* TODO (Sean): Include Logic to handle retrieving of editable data here and display in a modal component */}
|
160 | 167 | <Button className="edit-button" icon={<EditOutlined />}></Button>
|
@@ -198,6 +205,22 @@ export default function Home() {
|
198 | 205 | success("Filtered Successfully!");
|
199 | 206 | };
|
200 | 207 |
|
| 208 | + // Handler for show size change for pagination |
| 209 | + const onShowSizeChange: PaginationProps["onShowSizeChange"] = ( |
| 210 | + current, |
| 211 | + pageSize |
| 212 | + ) => { |
| 213 | + console.log(current); |
| 214 | + console.log(pageSize); |
| 215 | + setCurrentPage(current); |
| 216 | + setLimit(pageSize); |
| 217 | + }; |
| 218 | + |
| 219 | + // Handler for change in page jumper |
| 220 | + const onPageJump: PaginationProps["onChange"] = (pageNumber) => { |
| 221 | + setCurrentPage(pageNumber); |
| 222 | + }; |
| 223 | + |
201 | 224 | return (
|
202 | 225 | <div>
|
203 | 226 | {contextHolder}
|
@@ -274,6 +297,13 @@ export default function Home() {
|
274 | 297 | dataSource={questions}
|
275 | 298 | columns={columns}
|
276 | 299 | loading={isLoading}
|
| 300 | + pagination={{ |
| 301 | + total: totalCount, |
| 302 | + showSizeChanger: true, |
| 303 | + onShowSizeChange: onShowSizeChange, |
| 304 | + // showQuickJumper: true, |
| 305 | + onChange: onPageJump, |
| 306 | + }} |
277 | 307 | />
|
278 | 308 | </div>
|
279 | 309 | </div>
|
|
0 commit comments