@@ -17,11 +17,14 @@ import {
17
17
TableRow ,
18
18
} from '@/components/ui/table' ;
19
19
import { Button } from '@/components/ui/button' ;
20
- import { ArrowLeftIcon , ArrowRightIcon } from '@radix-ui/react-icons' ;
20
+ import {
21
+ ArrowLeftIcon ,
22
+ ArrowRightIcon ,
23
+ DoubleArrowLeftIcon ,
24
+ DoubleArrowRightIcon ,
25
+ } from '@radix-ui/react-icons' ;
21
26
import { Pagination , PaginationContent , PaginationItem } from '@/components/ui/pagination' ;
22
27
import { Input } from '@/components/ui/input' ;
23
-
24
- import { DIFFICULTY_OPTIONS , ROWS_PER_PAGE } from './logic' ;
25
28
import {
26
29
Select ,
27
30
SelectContent ,
@@ -30,6 +33,7 @@ import {
30
33
SelectValue ,
31
34
} from '@/components/ui/select' ;
32
35
import { useState } from 'react' ;
36
+ import { Link } from 'react-router-dom' ;
33
37
34
38
interface QuestionTableProps < TData , TValue > {
35
39
columns : ColumnDef < TData , TValue > [ ] ;
@@ -44,7 +48,7 @@ export function QuestionTable<TData, TValue>({
44
48
} : QuestionTableProps < TData , TValue > ) {
45
49
const [ pagination , setPagination ] = useState ( {
46
50
pageIndex : 0 ,
47
- pageSize : ROWS_PER_PAGE ,
51
+ pageSize : 12 ,
48
52
} ) ;
49
53
50
54
const [ columnFilters , setColumnFilters ] = useState < ColumnFiltersState > ( [ ] ) ;
@@ -74,7 +78,7 @@ export function QuestionTable<TData, TValue>({
74
78
< div className = 'flex items-center py-4' >
75
79
< div className = 'mr-2' >
76
80
< Select onValueChange = { handleStatusFilterChange } >
77
- < SelectTrigger className = 'w-[110px ]' >
81
+ < SelectTrigger className = 'w-[140px ]' >
78
82
< SelectValue placeholder = 'Status' />
79
83
</ SelectTrigger >
80
84
< SelectContent >
@@ -86,18 +90,14 @@ export function QuestionTable<TData, TValue>({
86
90
</ div >
87
91
< div className = 'mr-2' >
88
92
< Select onValueChange = { handleDifficultyFilterChange } >
89
- < SelectTrigger className = 'w-[110px ]' >
93
+ < SelectTrigger className = 'w-[140px ]' >
90
94
< SelectValue placeholder = 'Difficulty' />
91
95
</ SelectTrigger >
92
96
< SelectContent >
93
97
< SelectItem value = 'all' > All</ SelectItem >
94
- { DIFFICULTY_OPTIONS . map ( ( difficulty ) => {
95
- return (
96
- < SelectItem key = { difficulty . toLowerCase ( ) } value = { difficulty } >
97
- { difficulty }
98
- </ SelectItem >
99
- ) ;
100
- } ) }
98
+ < SelectItem value = 'Easy' > Easy</ SelectItem >
99
+ < SelectItem value = 'Medium' > Medium</ SelectItem >
100
+ < SelectItem value = 'Hard' > Hard</ SelectItem >
101
101
</ SelectContent >
102
102
</ Select >
103
103
</ div >
@@ -131,7 +131,9 @@ export function QuestionTable<TData, TValue>({
131
131
< TableRow key = { row . id } >
132
132
{ row . getVisibleCells ( ) . map ( ( cell ) => (
133
133
< TableCell key = { cell . id } >
134
- { flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) }
134
+ < Link to = { `/questions/${ row . id } ` } >
135
+ { flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) }
136
+ </ Link >
135
137
</ TableCell >
136
138
) ) }
137
139
</ TableRow >
@@ -149,6 +151,16 @@ export function QuestionTable<TData, TValue>({
149
151
< Pagination className = 'flex items-center justify-end space-x-2 py-4' >
150
152
< PaginationContent >
151
153
< PaginationItem >
154
+ < Button
155
+ variant = 'outline'
156
+ size = 'sm'
157
+ onClick = { ( ) => table . firstPage ( ) }
158
+ disabled = { ! table . getCanPreviousPage ( ) }
159
+ >
160
+ < DoubleArrowLeftIcon />
161
+ </ Button >
162
+ </ PaginationItem >
163
+ < PaginationItem className = 'mr-1' >
152
164
< Button
153
165
variant = 'outline'
154
166
size = 'sm'
@@ -158,7 +170,10 @@ export function QuestionTable<TData, TValue>({
158
170
< ArrowLeftIcon />
159
171
</ Button >
160
172
</ PaginationItem >
161
- < PaginationItem >
173
+ < PaginationItem className = 'text-sm' >
174
+ { table . getState ( ) . pagination . pageIndex + 1 } of { table . getPageCount ( ) }
175
+ </ PaginationItem >
176
+ < PaginationItem className = 'ml-1' >
162
177
< Button
163
178
variant = 'outline'
164
179
size = 'sm'
@@ -168,6 +183,16 @@ export function QuestionTable<TData, TValue>({
168
183
< ArrowRightIcon />
169
184
</ Button >
170
185
</ PaginationItem >
186
+ < PaginationItem >
187
+ < Button
188
+ variant = 'outline'
189
+ size = 'sm'
190
+ onClick = { ( ) => table . lastPage ( ) }
191
+ disabled = { ! table . getCanNextPage ( ) }
192
+ >
193
+ < DoubleArrowRightIcon />
194
+ </ Button >
195
+ </ PaginationItem >
171
196
</ PaginationContent >
172
197
</ Pagination >
173
198
</ div >
0 commit comments