diff --git a/website/src/views/planner/PlannerYear.tsx b/website/src/views/planner/PlannerYear.tsx index 1a1fe57aae..9a505a9b08 100644 --- a/website/src/views/planner/PlannerYear.tsx +++ b/website/src/views/planner/PlannerYear.tsx @@ -1,4 +1,4 @@ -import { PureComponent } from 'react'; +import { PureComponent, Ref, createRef } from 'react'; import classnames from 'classnames'; import { flatMap, size, sortBy, toPairs, values } from 'lodash'; @@ -24,14 +24,31 @@ type Props = Readonly<{ type State = { readonly showSpecialSem: boolean; + readonly currentYearCardRef: Ref; }; export default class PlannerYear extends PureComponent { override state = { // Always display Special Terms I and II if either one has modules showSpecialSem: this.hasSpecialTermModules(), + currentYearCardRef: createRef(), }; + override componentDidMount() { + if (this.props.year !== config.academicYear) { + return; + } + const currentYearCard = this.state.currentYearCardRef.current; + const parentContainer = currentYearCard?.parentElement; + if (!currentYearCard || !parentContainer) { + return; + } + parentContainer.scrollTo({ + left: currentYearCard.offsetLeft - parentContainer.offsetLeft, + behavior: 'smooth', + }); + } + hasSpecialTermModules() { const { semesters } = this.props; return size(semesters[3]) > 0 || size(semesters[4]) > 0; @@ -72,6 +89,7 @@ export default class PlannerYear extends PureComponent { return (