Skip to content

Commit

Permalink
website: planner: Autoscroll to current year card (#3640)
Browse files Browse the repository at this point in the history
Co-authored-by: Kok Rui Wong <[email protected]>
Co-authored-by: Zhao Wei Liew <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent 599ced4 commit d481855
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion website/src/views/planner/PlannerYear.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PureComponent } from 'react';
import { PureComponent, createRef } from 'react';
import classnames from 'classnames';
import { flatMap, size, sortBy, toPairs, values } from 'lodash';

Expand Down Expand Up @@ -28,11 +28,25 @@ type State = {
};

export default class PlannerYear extends PureComponent<Props, State> {
readonly currentYearCardRef = createRef<HTMLDivElement>();

override state = {
// Always display Special Terms I and II if either one has modules
showSpecialSem: this.hasSpecialTermModules(),
};

override componentDidMount() {
if (this.props.year !== config.academicYear) {
return;
}
const currentYearCard = this.currentYearCardRef.current;
if (currentYearCard) {
currentYearCard.scrollIntoView({
inline: 'start',
});
}
}

hasSpecialTermModules() {
const { semesters } = this.props;
return size(semesters[3]) > 0 || size(semesters[4]) > 0;
Expand Down Expand Up @@ -73,6 +87,7 @@ export default class PlannerYear extends PureComponent<Props, State> {

return (
<section
ref={year === config.academicYear ? this.currentYearCardRef : undefined}
key={year}
className={classnames(styles.year, {
[styles.currentYear]: year === config.academicYear,
Expand Down

0 comments on commit d481855

Please sign in to comment.