Skip to content

Commit fbb113b

Browse files
authored
Random question generator button is added (#240)
1 parent 3329346 commit fbb113b

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/components/Table/index.js

+36-2
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,
@@ -232,7 +237,36 @@ const Table = () => {
232237
Filter: SelectCheckedColumnFilter,
233238
},
234239
{
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+
},
236270
accessor: 'questions',
237271
disableSortBy: true,
238272
Cell: cellInfo => {

0 commit comments

Comments
 (0)