From 9e1106a269a4f811ce3ce53c0649d2a38fad3c8a Mon Sep 17 00:00:00 2001 From: Shashank5665 Date: Sat, 20 Aug 2022 09:08:30 +0530 Subject: [PATCH 1/6] New changes with randomQuestion --- package-lock.json | 3 ++- src/components/Table/index.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index e2304b67..a704b4d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9158,7 +9158,8 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.1.tgz", "integrity": "sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw==", "os": [ - "darwin" + "darwin", + "win32" ], "engines": { "node": "^8.16.0 || ^10.6.0 || >=11.0.0" diff --git a/src/components/Table/index.js b/src/components/Table/index.js index bfe152cd..fff57a01 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -362,6 +362,26 @@ 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 ( + + ); + }, + accessor: 'randomQuestion', + }, ], }, ], From e2abe6a392dc7c3dca9118914a23cae979dea912 Mon Sep 17 00:00:00 2001 From: Shashank5665 Date: Sun, 21 Aug 2022 09:01:30 +0530 Subject: [PATCH 2/6] changes to randomQuestion button --- package-lock.json | 3 +- src/components/Table/index.js | 56 +++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index a704b4d4..e2304b67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9158,8 +9158,7 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.1.tgz", "integrity": "sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw==", "os": [ - "darwin", - "win32" + "darwin" ], "engines": { "node": "^8.16.0 || ^10.6.0 || >=11.0.0" diff --git a/src/components/Table/index.js b/src/components/Table/index.js index fff57a01..83b30bb2 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -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, @@ -201,7 +206,34 @@ const Table = () => { }, }, { - Header: 'Questions', + Header: () => { + return ( + <> +
+ Questions{' '} + +
+ + ); + }, accessor: 'questions', disableSortBy: true, Cell: cellInfo => { @@ -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 ( - - ); - }, - accessor: 'randomQuestion', - }, ], }, ], From 05a0559fe40c4529a1d77b75ca02ef1190b1e98a Mon Sep 17 00:00:00 2001 From: Shashank5665 Date: Sun, 21 Aug 2022 19:17:24 +0530 Subject: [PATCH 3/6] created a seperate function to generate ramdom question Id. --- src/components/Table/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/Table/index.js b/src/components/Table/index.js index 83b30bb2..6ffab9b0 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -207,6 +207,12 @@ const Table = () => { }, { Header: () => { + const randomQuestion = () => { + const random = Math.floor(Math.random() * questions.length); + const questionId = questions[random].id; + const questionSlug = questions[questionId].url; + window.open(`${questionSlug}`, '_blank'); + }; return ( <>
{ > Questions{' '}