Skip to content

Commit 8b82a26

Browse files
authored
Fixed randomQuestions - now it uses filtered questions (seanprashad#295)
1 parent ffc85f0 commit 8b82a26

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/components/Table/index.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,16 @@ const Table = () => {
226226
Filter: SelectCheckedColumnFilter,
227227
},
228228
{
229-
Header: () => {
229+
/* eslint-disable react/prop-types */
230+
Header: ({ filteredRows }) => {
231+
const disableRandomQuestionButton = filteredRows.length === 0;
232+
230233
const randomQuestion = () => {
231-
const filteredByCheckboxQuestions = filteredByCheckbox();
232-
const filteredQuestions = filteredByCheckboxQuestions.length
233-
? filteredByCheckboxQuestions
234-
: questions;
235-
const random = Math.floor(
236-
Math.random() * filteredQuestions.length,
237-
);
238-
const questionSlug = filteredQuestions[random].slug;
234+
const random = Math.floor(Math.random() * filteredRows.length);
235+
const randomFilteredRow = filteredRows[random];
236+
const questionSlug = randomFilteredRow.original.slug;
237+
/* eslint-enable react/prop-types */
238+
239239
window.open(
240240
`https://leetcode.com/problems/${questionSlug}/`,
241241
'_blank',
@@ -269,6 +269,7 @@ const Table = () => {
269269
>
270270
Questions{' '}
271271
<Button
272+
disabled={disableRandomQuestionButton}
272273
onClick={randomQuestion}
273274
color="dark"
274275
id="random-question-button"

0 commit comments

Comments
 (0)