@@ -26,13 +26,17 @@ import {
26
26
deleteSingleLeetcodeQuestion ,
27
27
getLeetcodeDashboardData ,
28
28
} from "@/api/leetcode-dashboard" ;
29
- import { QuestionMinified } from "@/types/find-match" ;
29
+ import { QuestionDifficulty , QuestionMinified } from "@/types/find-match" ;
30
30
import MoonLoader from "react-spinners/MoonLoader" ;
31
31
import EditQuestionDialog from "@/app/(auth)/leetcode-dashboard/EditQuestionDialog" ;
32
32
import { motion } from "framer-motion" ;
33
33
import Modal from "react-modal" ;
34
34
import Swal from "sweetalert2" ;
35
35
import { useEffect , useState } from "react" ;
36
+ import { Input } from "@/components/ui/input" ;
37
+ import { ListFilter , Search } from "lucide-react" ;
38
+ import { MultiSelect } from "@/components/ui/multiselect" ;
39
+ import { capitalizeWords } from "@/utils/string_utils" ;
36
40
37
41
const Cell = ( {
38
42
className,
@@ -105,6 +109,20 @@ export function LeetcodeDashboardTable({
105
109
} ) ;
106
110
107
111
const [ totalPages , setTotalPage ] = React . useState < number > ( 1 ) ;
112
+ const [ searchTitle , setSearchTitle ] = React . useState < string > ( "" ) ;
113
+ const [ searchDifficulty , setSearchDifficulty ] = React . useState < string [ ] > ( [ ] ) ;
114
+ const [ isFilterOpen , setIsFilterOpen ] = React . useState < boolean > ( false ) ;
115
+
116
+ const questionDifficulty = Object . values ( QuestionDifficulty ) . map ( ( q1 ) => {
117
+ return {
118
+ label : capitalizeWords ( q1 ) ,
119
+ value : q1 ,
120
+ } ;
121
+ } ) ;
122
+
123
+ const toggleDropdown = ( ) => {
124
+ setIsFilterOpen ( ! isFilterOpen ) ;
125
+ } ;
108
126
109
127
const columns : ColumnDef < QuestionMinified > [ ] = [
110
128
{
@@ -184,12 +202,21 @@ export function LeetcodeDashboardTable({
184
202
useEffect ( ( ) => {
185
203
getLeetcodeDashboardData (
186
204
pagination . pageIndex + 1 ,
187
- pagination . pageSize
205
+ pagination . pageSize ,
206
+ searchTitle ,
207
+ searchDifficulty
188
208
) . then ( ( data ) => {
189
- setData ( data . questions ) ;
190
209
setTotalPage ( data . totalPages ) ;
210
+ if ( data . totalPages < pagination . pageIndex + 1 ) {
211
+ setPagination ( ( prev ) => ( {
212
+ ...prev ,
213
+ pageIndex : data . totalPages - 1 ,
214
+ } ) ) ;
215
+ } else {
216
+ setData ( data . questions ) ;
217
+ }
191
218
} ) ;
192
- } , [ refreshKey , pagination . pageIndex ] ) ;
219
+ } , [ refreshKey , pagination . pageIndex , searchTitle , searchDifficulty ] ) ;
193
220
194
221
const table = useReactTable ( {
195
222
data,
@@ -211,7 +238,44 @@ export function LeetcodeDashboardTable({
211
238
< TableHeader className = "w-full" >
212
239
< TableRow className = "text-white bg-primary-900 font-medium hover:bg-transparent h-[5rem] text-md" >
213
240
< TableCell colSpan = { 5 } className = "pl-10" >
214
- Past Collaborations
241
+ < div className = "flex items-center" >
242
+ < span > LeetCode Question Bank</ span >
243
+ < span className = "ml-auto flex place-items-center gap-6 pr-4" >
244
+ < div className = "relative" >
245
+ < Search className = "absolute left-3 top-1/2 transform -translate-y-1/2 text-primary-400 w-4" />
246
+ < Input
247
+ className = "w-[16rem] pl-10 !placeholder-primary-400"
248
+ placeholder = "Search Question Name"
249
+ onChange = { ( e ) => setSearchTitle ( e . target . value ) }
250
+ />
251
+ </ div >
252
+ < div className = "relative" >
253
+ < Button
254
+ className = "gap-2 bg-transparent text-primary-400 border-[1px] hover:bg-primary-300"
255
+ onClick = { toggleDropdown }
256
+ >
257
+ < ListFilter />
258
+ Filter By
259
+ </ Button >
260
+ { isFilterOpen && (
261
+ < div className = "absolute right-0 mt-2 h-80 w-52 bg-primary-800 text-primary-300 border border-gray-300 rounded shadow-lg z-10" >
262
+ < div className = "flex flex-col place-items-center mt-4" >
263
+ < div className = "w-[90%]" >
264
+ < div className = "text-xs" > Difficulty</ div >
265
+ < MultiSelect
266
+ options = { questionDifficulty }
267
+ onValueChange = { setSearchDifficulty }
268
+ placeholder = "Select options"
269
+ variant = "inverted"
270
+ className = "mt-1"
271
+ />
272
+ </ div >
273
+ </ div >
274
+ </ div >
275
+ ) }
276
+ </ div >
277
+ </ span >
278
+ </ div >
215
279
</ TableCell >
216
280
</ TableRow >
217
281
{ table . getHeaderGroups ( ) . map ( ( headerGroup ) => (
0 commit comments