refactor(UserSchedule): index by a unique id rather than name (#166)
* refactor(UserSchedule): index by a unique id rather than name * refactor: Update parameter names in schedule function jsdocs * refactor: change more instances of .name to .id * refactor: Fix typo in variable name and update references * refactor: Remove console.log statement * fix(chromatic): Update ScheduleListItem story * refactor: remove unused eslint rule
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { Serialized } from 'chrome-extension-toolkit';
|
||||
|
||||
import { generateRandomId } from '../util/random';
|
||||
import { Course } from './Course';
|
||||
|
||||
/**
|
||||
@@ -7,6 +8,7 @@ import { Course } from './Course';
|
||||
*/
|
||||
export class UserSchedule {
|
||||
courses: Course[];
|
||||
id: string;
|
||||
name: string;
|
||||
hours: number;
|
||||
/** Unix timestamp of when the schedule was last updated */
|
||||
@@ -14,12 +16,10 @@ export class UserSchedule {
|
||||
|
||||
constructor(schedule: Serialized<UserSchedule>) {
|
||||
this.courses = schedule.courses.map(c => new Course(c));
|
||||
this.id = schedule.id ?? generateRandomId();
|
||||
this.name = schedule.name;
|
||||
this.hours = 0;
|
||||
for (const course of this.courses) {
|
||||
this.hours += course.creditHours;
|
||||
}
|
||||
this.updatedAt = schedule.updatedAt;
|
||||
this.hours = this.courses.reduce((acc, c) => acc + c.creditHours, 0);
|
||||
this.updatedAt = schedule.updatedAt ?? 0;
|
||||
}
|
||||
|
||||
containsCourse(course: Course): boolean {
|
||||
|
||||
Reference in New Issue
Block a user