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

website: planner: Autoscroll to current year card #3640

Conversation

jacobkwan
Copy link
Contributor

@jacobkwan jacobkwan commented Nov 9, 2023

Context

Fixes #3639: Autoscroll Course Planner to current year on first render

Implementation

  1. Add currentYearCardRef state variable
  2. Only pass currentYearCardRef to the PlannerYear card for the current year of enrolment
  3. Define componentDidMount method in PlannerYear
    • Uses currentYearCardRef to get parent container and calculate offsets for child and parent
    • scrolls the desired amount (with smooth effect)

Before

Screen.Recording.2023-11-09.at.10.40.21.PM.mov

After

Screen.Recording.2023-11-09.at.10.49.25.PM.mov

Other Information

Copy link

vercel bot commented Nov 9, 2023

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 Nov 25, 2024 7:36am
nusmods-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 7:36am

Copy link

vercel bot commented Nov 9, 2023

@jacobkwan is attempting to deploy a commit to a Personal Account owned by @nusmodifications on Vercel.

@nusmodifications first needs to authorize it.

Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 54.69%. Comparing base (988c6fd) to head (f3b54ed).
Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
website/src/views/planner/PlannerYear.tsx 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3640      +/-   ##
==========================================
+ Coverage   54.52%   54.69%   +0.17%     
==========================================
  Files         274      274              
  Lines        6076     6099      +23     
  Branches     1455     1460       +5     
==========================================
+ Hits         3313     3336      +23     
  Misses       2763     2763              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@kokrui kokrui self-requested a review March 8, 2024 13:02
Copy link
Member

@ZhangYiJiang ZhangYiJiang left a comment

Choose a reason for hiding this comment

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

I think this is a good idea, although ref is used incorrectly here

@@ -24,14 +24,31 @@ type Props = Readonly<{

type State = {
readonly showSpecialSem: boolean;
readonly currentYearCardRef: Ref<HTMLDivElement>;
Copy link
Member

Choose a reason for hiding this comment

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

ref should not be stored in state, see https://react.dev/reference/react/createRef

}
parentContainer.scrollTo({
left: currentYearCard.offsetLeft - parentContainer.offsetLeft,
behavior: 'smooth',
Copy link
Member

Choose a reason for hiding this comment

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

For scrolling on component mount you probably don't want smooth, it's better for the component to appear already scrolled to the correct location.

if (!currentYearCard || !parentContainer) {
return;
}
parentContainer.scrollTo({
Copy link
Member

Choose a reason for hiding this comment

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

Could consider using scrollIntoView instead, that would avoid having to do math to figure out exact offset

@kokrui kokrui removed their request for review March 12, 2024 07:01
@zwliew zwliew changed the title Autoscroll Course Planner to current year card website: planner: Autoscroll to current year card Nov 25, 2024
@zwliew zwliew merged commit d481855 into nusmodifications:master Nov 25, 2024
4 of 6 checks passed
@zwliew
Copy link
Member

zwliew commented Nov 25, 2024

It's been a long time but thanks for your contribution!

@jacobkwan
Copy link
Contributor Author

It's been a long time but thanks for your contribution!

ty chads

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.

Autoscroll Course Planner to current year on load
4 participants