Skip to content

New changes with randomQuestion #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 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,33 @@ const Table = () => {
},
},
{
Header: 'Questions',
Header: () => {
const randomQuestion = () => {
const random = Math.floor(Math.random() * questions.length);
const questionId = questions[random].id;
const questionSlug = questions[questionId].url;
Copy link
Owner

@seanprashad seanprashad Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to rebase off the master branch? url is no longer used there and if we were to land this PR now, it wouldn't work! To rebase means to pull in the latest commits from the branch we're targeting, ie. master, and then apply all of your commits in the order you made them. It can seem tricky if it's your first time doing it - let me know if you'd like for me to walk you through it 👍🏽

Once you've rebased..

const questionSlug = questions[questionId].url;

will need to be changed to..

const questionSlug = questions[questionId].slug; 

and then we'll need to update window.open() as so:

window.open(`https://leetcode.com/problems/${questionSlug}/`, '_blank');

See questions.json here for how the data is presented - we no longer store the https://leetcode.com/problems/ portion since we know that is "static" in a sense - we only store the unique identifying part of the address, aka a "slug" (MDN docs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanprashad Yes, I am doing this for the first time, so can you please assist me😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I typed these commands till now, I am not sure what to do after this..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: I figured it out, I was able to successfully rebase the master branch, and new changes are now present in the master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, seems like, after adding these changes..

const questionSlug = questions[questionId].slug; 
window.open(`https://leetcode.com/problems/${questionSlug}/`, '_blank');

There is a bug, the questionSlug is undefined, because of which leetcode is not able to find the page.
image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you needed to pull from a different remote, ie. the master branch from seanprashad/leetcode-patterns instead of master from Shashank5665/leetcode-patterns.

We can see the remote repos you have via git remote -v:

 ✘ sprashad@home  ~/projects/leetcode-patterns   randomQuestion  git remote -v
origin  [email protected]:seanprashad/leetcode-patterns.git (fetch)
origin  [email protected]:seanprashad/leetcode-patterns.git (push)

As you can see above, I only have remote for the original repo (ie. the one you're submitting a PR to). You'll need to run the following to add mine as an "upstream" remote:

// This is for SSH - you might use HTTPS
git remote add upstream [email protected]:seanprashad/leetcode-patterns.git

Afterwards, you can verify we've correctly added my repo as a remote via git remote -v.

I think you can then run the following to pull the latest master branch from seanprashad/leetcode-patterns (which has the slug changes):

git checkout master
git pull upstream master
git checkout -
git rebase master
git push origin -f

Note that we'll need to force push after rebasing - this is because commit hashes change after rebasing, even though the contents of our commit doesn't!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @seanprashad, done with all the steps that you have mentioned, it took me a while to know what's going on, but surfing google a lil bit and with the help of your instructions, I have done it. Now, after starting the server, the feature works very well😁( with the slug inclusion ). I think everything is in place, So, is it just a pull request now?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Please do mark it as a PR and I'll review it when I get a chance!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @seanprashad !!

window.open(`${questionSlug}`, '_blank');
};
return (
<>
<div
style={{ whiteSpace: 'nowrap', display: 'inline-block' }}
>
Questions{' '}
<Button
onClick={randomQuestion}
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