@@ -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 ,
@@ -201,7 +206,34 @@ const Table = () => {
201
206
} ,
202
207
} ,
203
208
{
204
- Header : 'Questions' ,
209
+ Header : ( ) => {
210
+ return (
211
+ < >
212
+ < div
213
+ style = { { whiteSpace : 'nowrap' , display : 'inline-block' } }
214
+ >
215
+ Questions{ ' ' }
216
+ < Button
217
+ onClick = { ( ) => {
218
+ const random = Math . floor (
219
+ Math . random ( ) * questions . length ,
220
+ ) ;
221
+ const questionId = questions [ random ] . id ;
222
+ const questionSlug = questions [ questionId ] . url ;
223
+ window . open ( `${ questionSlug } ` , '_blank' ) ;
224
+ } }
225
+ color = "dark"
226
+ id = "random-question-button"
227
+ size = "sm"
228
+ >
229
+ < span data-tip = "Try a random question!" >
230
+ < FaRandom />
231
+ </ span >
232
+ </ Button >
233
+ </ div >
234
+ </ >
235
+ ) ;
236
+ } ,
205
237
accessor : 'questions' ,
206
238
disableSortBy : true ,
207
239
Cell : cellInfo => {
@@ -362,26 +394,6 @@ const Table = () => {
362
394
} ,
363
395
Filter : SelectColumnFilter ,
364
396
} ,
365
- // button to display a random question
366
- {
367
- randomQuestion : ( ) => {
368
- const random = Math . floor ( Math . random ( ) * questions . length ) ;
369
- const questionId = questions [ random ] . id ;
370
- return questionId ;
371
- } ,
372
- Header : ( ) => {
373
- return (
374
- < Button
375
- onClick = { ( ) => { } }
376
- color = "success"
377
- id = "random-question-button"
378
- >
379
- Random Question
380
- </ Button >
381
- ) ;
382
- } ,
383
- accessor : 'randomQuestion' ,
384
- } ,
385
397
] ,
386
398
} ,
387
399
] ,
0 commit comments