Skip to content

feat: support manual course editing#667

Merged
w568w merged 20 commits intoDanXi-Dev:mainfrom
sseu-buhzzi:20260313/feat-editable-course
Mar 19, 2026
Merged

feat: support manual course editing#667
w568w merged 20 commits intoDanXi-Dev:mainfrom
sseu-buhzzi:20260313/feat-editable-course

Conversation

@sseu-buhzzi
Copy link
Copy Markdown
Contributor

  • Introduces the ability to users to edit manually added courses.
  • Supports removing course times in the course editing dialog.
  • Supports sorting and deduplicating course times after user adds it.
  • Enhances i18n for days of weeks.

Close #666.

- Added `MANUALLY_ADDED_ROOM_ID` constant and `isManuallyAdded` getter
  to the `Course` model to replace hardcoded room ID.
- Renamed `courseRoomIdcontroller` to `courseRoomNameController` for
  consistency.
- Updated `ManuallyAddCourseDialog` to support an `initialCourse` for
  editing existing entries. It might be renamed then.
- Added `EditCourseEvent` and its stream listener to handle corse
  updates.
- Extract some common logics in `ManuallyAddCourseDialog` into separate
  functions.

# Conflicts:
#	lib/widget/dialogs/manually_add_course_dialog.dart
- Replace hardcoded `Constant.WeekDays` list with `DateFormat.E()`.
- Move `kMonday` anchor from `TimeTable` to `Constant` for centralized
  access.
- Update manual course dialogs and timetable to use the new method.
- Implement `Comparable` for `CourseTime` to support sorting by weekday
  and slot.
- Support removing a `CourseTime` by both clicking a button or swiping
  horizontally
@sseu-buhzzi sseu-buhzzi changed the title feat: refac feat: support manual course editing Mar 13, 2026
@w568w w568w requested review from Copilot and w568w March 14, 2026 10:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for editing manually added courses from the timetable UI, including updating existing course fields and managing course meeting times, while improving weekday i18n formatting across the app.

Changes:

  • Extend the manual course dialog to accept an initialCourse for editing, and support removing course times plus sorting/deduping after additions.
  • Add an edit action for manually added courses in the timetable page and wire it through an EditCourseEvent.
  • Centralize weekday string formatting via Constant.weekDay() and update relevant UI/data formatting to use it.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/widget/dialogs/manually_add_course_dialog_sub.dart Uses slot-count derived from timetable config and switches weekday label rendering to Constant.weekDay().
lib/widget/dialogs/manually_add_course_dialog.dart Supports editing via initialCourse, provides time tile removal UI, and attempts to sort/dedup added times.
lib/page/subpage_timetable.dart Adds edit event/subscription and shows an edit button for manually added courses.
lib/model/time_table.dart Adds Course.copyWith, Course.isManuallyAdded, and makes CourseTime comparable; updates weekday formatting usage.
lib/common/constant.dart Introduces Constant.weekDay() (intl-based) and moves the “reference Monday” constant here.
Comments suppressed due to low confidence (1)

lib/model/time_table.dart:355

  • CourseTime is used in Set operations (e.g., toSet() for dedup) and is now Comparable, but it still lacks operator==/hashCode. Without value equality (weekDay+slot), deduplication via Set<CourseTime> will not work and may leave duplicate times. Implement == and hashCode consistent with compareTo (and ideally keep it immutable).
class CourseTime implements Comparable<CourseTime> {
  //Monday is 0, Morning lesson is 0
  int weekDay, slot;

  CourseTime(this.weekDay, this.slot);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/widget/dialogs/manually_add_course_dialog.dart
Comment thread lib/page/subpage_timetable.dart Outdated
Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment thread lib/widget/dialogs/manually_add_course_dialog_sub.dart Outdated
@w568w
Copy link
Copy Markdown
Member

w568w commented Mar 14, 2026

Reminder: It might be worth taking a look at Copilot's suggestions too.

Even though I mentioned earlier that most of them aren't helpful, these specific ones actually seem to make sense.

To correctly deduplicate slots of courses.
- Deleted `lib/widget/dialogs/manually_add_course_dialog_sub.dart`.
- Appended the `AddCourseDialogSub` class and its state to
  `lib/widget/dialogs/manually_add_course_dialog.dart`.
Instead of new ID, remove the courses with the old ID. This ensures the
courses with the old ID to be deleted even though the user modified the
ID.

By the way, when the ID is not unique, all matching courses are deleted,
as this is the behaviour of the delete button.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds manual-course editing support in the timetable UI, including removing course times and improving weekday localization.

Changes:

  • Extend the manual add course dialog to support editing an existing course and removing selected time entries.
  • Add Course/CourseTime utilities (manual-course identifier, copyWith, Comparable/equality) to enable deduplication + sorting of times.
  • Centralize weekday display via Constant.weekDay() to improve i18n.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
lib/widget/dialogs/manually_add_course_dialog_sub.dart Removes the standalone slot-selection sub-dialog (logic moved inline).
lib/widget/dialogs/manually_add_course_dialog.dart Adds edit-mode support (initialCourse), dedup/sort on add, and UI to remove times.
lib/page/subpage_timetable.dart Introduces edit event flow and surfaces edit action for manually-added courses.
lib/model/time_table.dart Adds manual-course identifier helpers, Course.copyWith, and CourseTime ordering/equality.
lib/common/constant.dart Adds localized weekday helper (weekDay) and moves weekday formatting dependency here.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment thread lib/page/subpage_timetable.dart Outdated
@w568w
Copy link
Copy Markdown
Member

w568w commented Mar 15, 2026

Has GitHub upgraded the base model for their Copilot? 🤔

Those suggestions still look valid to me. Please take a look.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread lib/widget/dialogs/manually_add_course_dialog.dart
Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment thread lib/page/subpage_timetable.dart
Comment thread lib/page/subpage_timetable.dart Outdated
Comment thread lib/page/subpage_timetable.dart
- Implemented validation in `ManuallyAddCourseDialog` to ensure course
  IDs are non-empty and unique among existing manual courses.
- Refactored warning dialog logic into a helper method
  `_showWarningDialog`.
- Added localization strings for empty and conflicting course ID
  provided.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread lib/widget/dialogs/manually_add_course_dialog.dart Outdated
Comment on lines +50 to +56
final availableWeeks = newCourse.availableWeeks;
if (availableWeeks != null) {
// Populate staged course times from the initial course, and drop the old
// ones.
widget.courseAvailableList.clear();
widget.courseAvailableList.addAll(availableWeeks);
}
Comment on lines 229 to +231
PlatformDialogAction(
child: Text(S.of(context).ok),
onPressed: () {
Comment thread lib/l10n/intl_en.arb Outdated
@sseu-buhzzi
Copy link
Copy Markdown
Contributor Author

Some confirmations:

  • I have added some checking dialogs before updating the course IDs, disallowing users to set duplicated IDs.
  • When editing the ID, it will delete courses with the old ID, same with the delete button.

Are these OK?

@w568w
Copy link
Copy Markdown
Member

w568w commented Mar 19, 2026

Are these OK?

That's okay to me.

Copy link
Copy Markdown
Member

@w568w w568w left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution!

@w568w w568w merged commit 60aa3a5 into DanXi-Dev:main Mar 19, 2026
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.

[Feature Request] 支持修改手动加入的课程

3 participants