1
1
"use client" ;
2
2
import Header from "@/components/Header/header" ;
3
- import { Col , Layout , message , Row , Table } from "antd" ;
3
+ import { Col , Layout , message , PaginationProps , Row , Table } from "antd" ;
4
4
import { Content } from "antd/es/layout/layout" ;
5
5
import { CodeOutlined , HistoryOutlined } from "@ant-design/icons" ;
6
6
import "./styles.scss" ;
@@ -24,6 +24,13 @@ interface Submission {
24
24
historyDocRefId : string ;
25
25
}
26
26
27
+ interface TablePagination {
28
+ totalCount : number ;
29
+ totalPages : number ;
30
+ currentPage : number ;
31
+ limit : number ;
32
+ }
33
+
27
34
export default function QuestionPage ( ) {
28
35
const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ; // Store the states related to table's loading
29
36
@@ -59,6 +66,12 @@ export default function QuestionPage() {
59
66
const [ currentSubmissionId , setCurrentSubmissionId ] = useState <
60
67
string | undefined
61
68
> ( undefined ) ;
69
+ const [ paginationParams , setPaginationParams ] = useState < TablePagination > ( {
70
+ totalCount : 0 ,
71
+ totalPages : 0 ,
72
+ currentPage : 1 ,
73
+ limit : 3 ,
74
+ } ) ;
62
75
63
76
const state = EditorState . create ( {
64
77
doc : "" ,
@@ -71,6 +84,33 @@ export default function QuestionPage() {
71
84
] ,
72
85
} ) ;
73
86
87
+ // Handler for change in page jumper
88
+ const onPageJump : PaginationProps [ "onChange" ] = ( pageNumber ) => {
89
+ setPaginationParams ( ( prev ) => {
90
+ loadQuestionHistories ( pageNumber , paginationParams . limit ) ;
91
+ return { ...paginationParams , currentPage : pageNumber } ;
92
+ } ) ;
93
+ } ;
94
+
95
+ async function loadQuestionHistories ( currentPage : number , limit : number ) {
96
+ if ( username === undefined ) return ;
97
+ setIsHistoryLoading ( true ) ;
98
+ GetUserQuestionHistories ( username , docRefId , currentPage , limit )
99
+ . then ( ( data : any ) => {
100
+ setUserQuestionHistories ( data . histories ) ;
101
+ setPaginationParams ( {
102
+ ...paginationParams ,
103
+ totalCount : data . totalCount ,
104
+ totalPages : data . totalPages ,
105
+ currentPage : data . currentPage ,
106
+ limit : data . limit ,
107
+ } ) ;
108
+ } )
109
+ . finally ( ( ) => {
110
+ setIsHistoryLoading ( false ) ;
111
+ } ) ;
112
+ }
113
+
74
114
// When code editor page is initialised, fetch the particular question, and display in code editor
75
115
useEffect ( ( ) => {
76
116
if ( ! isLoading ) {
@@ -90,15 +130,7 @@ export default function QuestionPage() {
90
130
} , [ docRefId ] ) ;
91
131
92
132
useEffect ( ( ) => {
93
- if ( username === undefined ) return ;
94
- GetUserQuestionHistories ( username , docRefId )
95
- . then ( ( data : any ) => {
96
- console . log ( data ) ;
97
- setUserQuestionHistories ( data ) ;
98
- } )
99
- . finally ( ( ) => {
100
- setIsHistoryLoading ( false ) ;
101
- } ) ;
133
+ loadQuestionHistories ( paginationParams . currentPage , paginationParams . limit ) ;
102
134
} , [ username ] ) ;
103
135
104
136
useEffect ( ( ) => {
@@ -108,15 +140,14 @@ export default function QuestionPage() {
108
140
} , [ ] ) ;
109
141
110
142
useEffect ( ( ) => {
143
+ // Only show history if a history is selected
111
144
if ( currentSubmissionId === undefined ) return ;
112
145
113
146
const view = new EditorView ( {
114
147
state,
115
148
parent : editorRef . current || undefined ,
116
149
} ) ;
117
150
118
- // TODO: get from a specific history which was selected.
119
- // Show latest history by default, or load specific history
120
151
GetHistory ( currentSubmissionId ) . then ( ( data : any ) => {
121
152
const submittedAt = new Date ( data . createdAt ) ;
122
153
setSubmission ( {
@@ -202,8 +233,14 @@ export default function QuestionPage() {
202
233
style : { cursor : "pointer" } ,
203
234
} ;
204
235
} }
205
- scroll = { { y : "max-content" } }
206
236
loading = { isHistoryLoading }
237
+ pagination = { {
238
+ size : "small" ,
239
+ current : paginationParams . currentPage ,
240
+ total : paginationParams . totalCount ,
241
+ pageSize : paginationParams . limit ,
242
+ onChange : onPageJump ,
243
+ } }
207
244
/>
208
245
</ div >
209
246
</ div >
0 commit comments