Skip to content
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

random course picker button #3735

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Nimastic
Copy link

Hi I added a feature request: random course picker button in settings (first good issue)

Context

#3671
Feature Request: Random Course Picker

Implementation

I created api.ts in website/src/utils/api.ts to fetch list of modules from NUSMods API
I also created randomCoursePicker.ts in website/src/utils/randomCoursePicker.ts to fetch a random course from the list of modules fetched from the API
Lastly I added button and function in website/src/views/settings/SettingsContainer.tsx for picking a random course
Overall, I created a random course picker button in the settings

ezgif-2-7618a9ce9f

Other Information

Hi I'm new to this as both a contributor on this repository and as an OS contributor. Do let me know if I have done anything wrongly.
I wasn't too sure where to add the button, hence i added it into settings. Do let me know if it isn't the right place to add it.

Hope to learn more :)

added a random course picker button in settings (first good issue)
Copy link

vercel bot commented Jun 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nusmods-export ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 19, 2024 2:06pm
nusmods-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 19, 2024 2:06pm

Copy link

vercel bot commented Jun 21, 2024

@Nimastic is attempting to deploy a commit to the modsbot's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@ravern ravern left a comment

Choose a reason for hiding this comment

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

Thank you very much for the PR! We're glad to be the first open-source project you're contributing to :)

I've tested this locally and can confirm it works.

I think that placing the button in the settings is a great choice! Would it be possible to shift it above the "Privacy" section?

Unfortunately, I'll have to request some changes, on the grounds of code convention. See below for comments.

Comment on lines +1 to +6
{
"name": "nusmods",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you remove package-lock.json and yarn.lock?

They both seem like artefacts from an accidental yarn install and npm install from the root of the repository.

Comment on lines +5 to +13
export const fetchModules = async () => {
try {
const response = await axios.get(`${BASE_URL}/moduleList.json`);
return response.data;
} catch (error) {
console.error('Error fetching modules:', error);
return [];
}
};
Copy link
Member

Choose a reason for hiding this comment

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

Can I check if there's a reason you added fetchModules to explicitly fetch all modules?

The module list should be available in Redux store, see website/src/types/state.ts for the structure of the store.

}
const randomIndex = Math.floor(Math.random() * courses.length);
const randomCourse = courses[randomIndex];
console.log('Random Course:', randomCourse);
Copy link
Member

Choose a reason for hiding this comment

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

We generally don't want to leave console.logs in production code. I think in this case, they aren't 100% necessary for the feature to work.

Copy link
Member

Choose a reason for hiding this comment

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

There's one higher up as well (oops)

const handleRandomCourseClick = async () => {
const randomCourse = await getRandomCourse(); // Fetch random course from API
if (randomCourse && randomCourse.moduleCode) {
history.push(`/courses/${randomCourse.moduleCode}`);
Copy link
Member

Choose a reason for hiding this comment

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

Could you "generate" the route to push using modulePage from website/src/views/routes/paths.ts?

@shiva-karthick
Copy link
Contributor

shiva-karthick commented Sep 6, 2024

Hi, if this issue is not taken care of, I can help to settle this PR :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants