Skip to content
Prev Previous commit
Next Next commit
changes to randomQuestion button
  • Loading branch information
Shashank5665 committed Aug 21, 2022
commit e2abe6a392dc7c3dca9118914a23cae979dea912
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 34 additions & 22 deletions src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
import Toggle from 'react-toggle';
import ReactTooltip from 'react-tooltip';
import { useTable, useFilters, useSortBy } from 'react-table';
import { FaLock, FaExternalLinkAlt, FaQuestionCircle } from 'react-icons/fa';
import {
FaLock,
FaExternalLinkAlt,
FaRandom,
FaQuestionCircle,
} from 'react-icons/fa';
import {
DefaultColumnFilter,
SelectDifficultyColumnFilter,
Expand Down Expand Up @@ -201,7 +206,34 @@ const Table = () => {
},
},
{
Header: 'Questions',
Header: () => {
return (
<>
<div
style={{ whiteSpace: 'nowrap', display: 'inline-block' }}
>
Questions{' '}
<Button
onClick={() => {
const random = Math.floor(
Math.random() * questions.length,
);
const questionId = questions[random].id;
const questionSlug = questions[questionId].url;
window.open(`${questionSlug}`, '_blank');
}}
color="dark"
id="random-question-button"
size="sm"
>
<span data-tip="Try a random question!">
<FaRandom />
</span>
</Button>
</div>
</>
);
},
accessor: 'questions',
disableSortBy: true,
Cell: cellInfo => {
Expand Down Expand Up @@ -362,26 +394,6 @@ const Table = () => {
},
Filter: SelectColumnFilter,
},
// button to display a random question
{
randomQuestion: () => {
const random = Math.floor(Math.random() * questions.length);
const questionId = questions[random].id;
return questionId;
},
Header: () => {
return (
<Button
onClick={() => {}}
color="success"
id="random-question-button"
>
Random Question
</Button>
);
},
accessor: 'randomQuestion',
},
],
},
],
Expand Down