File tree 1 file changed +36
-2
lines changed
1 file changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,12 @@ import {
14
14
import Toggle from 'react-toggle' ;
15
15
import ReactTooltip from 'react-tooltip' ;
16
16
import { useTable , useFilters , useSortBy } from 'react-table' ;
17
- import { FaLock , FaExternalLinkAlt , FaQuestionCircle } from 'react-icons/fa' ;
17
+ import {
18
+ FaLock ,
19
+ FaExternalLinkAlt ,
20
+ FaRandom ,
21
+ FaQuestionCircle ,
22
+ } from 'react-icons/fa' ;
18
23
import {
19
24
DefaultColumnFilter ,
20
25
SelectDifficultyColumnFilter ,
@@ -232,7 +237,36 @@ const Table = () => {
232
237
Filter : SelectCheckedColumnFilter ,
233
238
} ,
234
239
{
235
- Header : 'Questions' ,
240
+ Header : ( ) => {
241
+ const randomQuestion = ( ) => {
242
+ const random = Math . floor ( Math . random ( ) * questions . length ) ;
243
+ const questionId = questions [ random ] . id ;
244
+ const questionSlug = questions [ questionId ] . slug ;
245
+ window . open (
246
+ `https://leetcode.com/problems/${ questionSlug } /` ,
247
+ '_blank' ,
248
+ ) ;
249
+ } ;
250
+ return (
251
+ < >
252
+ < div
253
+ style = { { whiteSpace : 'nowrap' , display : 'inline-block' } }
254
+ >
255
+ Questions{ ' ' }
256
+ < Button
257
+ onClick = { randomQuestion }
258
+ color = "dark"
259
+ id = "random-question-button"
260
+ size = "sm"
261
+ >
262
+ < span data-tip = "Try a random question!" >
263
+ < FaRandom />
264
+ </ span >
265
+ </ Button >
266
+ </ div >
267
+ </ >
268
+ ) ;
269
+ } ,
236
270
accessor : 'questions' ,
237
271
disableSortBy : true ,
238
272
Cell : cellInfo => {
You can’t perform that action at this time.
0 commit comments