Skip to content

Refactor calendar.js.jsx into TypeScript components - #1831

Open
Purplegaze wants to merge 5 commits into
Courseography:masterfrom
Purplegaze:typescript-calendar
Open

Purplegaze wants to merge 5 commits into
Courseography:masterfrom
Purplegaze:typescript-calendar

Conversation

@Purplegaze

@Purplegaze Purplegaze commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Proposed Changes

Refactors js/components/grid/calendar.js.jsx into separate TypeScript components. Analogue to #1830.

Minor changes:

  • made the width attribute of a LectureTimeframe mandatory, as I believe it's always defined. This is to avoid type checking issues where null values are not expected.
  • removed an unused parameter in TimetableHeader

@PeanutPiglet Since we did these analogous tasks individually, I anticipate we will now need to work together to amalgamate our types and make sure they don't conflict with each other.

...

Screenshots of your changes (if applicable)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
✨ New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality) X
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CI checks have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

Now that Y-courses are in the database, I've noticed they get populated into the timetable grid twice, conflicting with themselves. I'd be happy to fix that in a separate PR after this is done.

@coveralls

coveralls commented Nov 13, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 43508803579

Coverage increased (+0.01%) to 61.57%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 39 uncovered changes across 5 files (83 of 122 lines covered, 68.03%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
js/components/grid/calendar.ts 55 28 50.91%
js/components/grid/TimetableRow.tsx 31 25 80.65%
js/components/grid/Row.tsx 15 12 80.0%
js/components/grid/TimetableHeader.tsx 11 9 81.82%
js/components/grid/Timetable.tsx 5 4 80.0%
Total (7 files) 122 83 68.03%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4302
Covered Lines: 2700
Line Coverage: 62.76%
Relevant Branches: 1009
Covered Branches: 570
Branch Coverage: 56.49%
Branches in Coverage %: Yes
Coverage Strength: 157.98 hits per line

💛 - Coveralls

@david-yz-liu david-yz-liu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work, @Purplegaze. I just left a few inline comments

@@ -0,0 +1,154 @@
import { LectureTimeframe } from "../common/types"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

throughout, use type-only imports for identifiers that are only imported for type annotations

let rawLectures = lectureSections.map((lectureSection, _index, selectedLectures) =>
createNewLectures(lectureSection, selectedLectures)
);
let lectures = ([] as LectureTimeframe[]).concat.apply([], rawLectures);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether there's any type inference possible here; rather than using as, can you annotate let lecture: LectureTimeframe[] = ... instead?

});

// Organize the structure of the <fallSession> and <springSession> 2-D dictionaries
let fallSession: TimetableMap, springSession: TimetableMap;[fallSession, springSession] = initializeSessions(lectures);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The original code here was a bit awkward. If initializeSessions has a return type annotation I don't think you need to annotate the variables, and instead just do

let [fallSession, springSession] = initializeSessions(lectures);

* @param timetableMap the map of intervals to active lectures
*/
const storeWidths = (timetableMap: TimetableMap): Record<number, number[]> => {
const widths = {} as Record<number, number[]>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of using as, I think you can move the type annotation to the variable directly:

let widths: Record<...> = ...

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