Skip to content

Commit fffdfae

Browse files
committed
Setup pagination for question service function and frontend component
1 parent 58640b8 commit fffdfae

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

apps/question-service/src/app/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function Home() {
3737
const [totalCount, setTotalCount] = useState<number | undefined>(undefined); // Store the total count of questions
3838
const [totalPages, setTotalPages] = useState<number | undefined>(undefined); // Store the total number of pages
3939
const [currentPage, setCurrentPage] = useState<number | undefined>(undefined); // Store the current page
40-
const [limit, setLimit] = useState<number | undefined>(undefined); // Store the quantity of questions to be displayed
40+
const [limit, setLimit] = useState<number | undefined>(10); // Store the quantity of questions to be displayed
4141
const [isLoading, setIsLoading] = useState<boolean>(true); // Store the states related to table's loading
4242

4343
// Filtering States
@@ -78,15 +78,15 @@ export default function Home() {
7878
setIsLoading(true);
7979
}
8080

81-
GetQuestions().then((data) => {
81+
GetQuestions(currentPage, limit).then((data) => {
8282
setQuestions(data.questions);
8383
setTotalCount(data.totalCount);
8484
setTotalPages(data.totalPages);
8585
setCurrentPage(data.currentPage);
8686
setLimit(data.limit);
8787
setIsLoading(false);
8888
});
89-
}, []);
89+
}, [limit, currentPage]);
9090

9191
// Table column specification
9292
const columns: TableProps<Question>["columns"] = [
@@ -167,6 +167,8 @@ export default function Home() {
167167
current,
168168
pageSize
169169
) => {
170+
console.log(current);
171+
console.log(pageSize);
170172
setCurrentPage(current);
171173
setLimit(pageSize);
172174
};
@@ -256,7 +258,7 @@ export default function Home() {
256258
total: totalCount,
257259
showSizeChanger: true,
258260
onShowSizeChange: onShowSizeChange,
259-
showQuickJumper: true,
261+
// showQuickJumper: true,
260262
onChange: onPageJump,
261263
}}
262264
/>

apps/question-service/src/app/services/question.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const GetQuestions = async (
3030
let query_params = "";
3131

3232
if (currentPage) {
33-
query_params += `?currentPage=${currentPage}`;
33+
query_params += `?offset=${(currentPage - 1) * 10}`;
3434
}
3535

3636
if (limit) {

0 commit comments

Comments
 (0)