Skip to content

Commit e2abe6a

Browse files
committed
changes to randomQuestion button
1 parent 9e1106a commit e2abe6a

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Table/index.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import {
1414
import Toggle from 'react-toggle';
1515
import ReactTooltip from 'react-tooltip';
1616
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';
1823
import {
1924
DefaultColumnFilter,
2025
SelectDifficultyColumnFilter,
@@ -201,7 +206,34 @@ const Table = () => {
201206
},
202207
},
203208
{
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+
},
205237
accessor: 'questions',
206238
disableSortBy: true,
207239
Cell: cellInfo => {
@@ -362,26 +394,6 @@ const Table = () => {
362394
},
363395
Filter: SelectColumnFilter,
364396
},
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-
},
385397
],
386398
},
387399
],

0 commit comments

Comments
 (0)