wrote all course/schedule background messages with handlers

This commit is contained in:
Sriram Hariharan
2023-09-17 20:58:22 -05:00
parent 6061295e0a
commit 52431747ee
12 changed files with 159 additions and 7 deletions

View File

@@ -1,7 +1,44 @@
import { Course } from '../types/Course';
export interface UserScheduleMessages {
/**
* Add a course to a schedule
* @param data the schedule name and course to add
*/
addCourse: (data: { scheduleName: string; course: Course }) => void;
/**
* Remove a course from a schedule
* @param data the schedule name and course to remove
*/
removeCourse: (data: { scheduleName: string; course: Course }) => void;
/**
* Clears all courses from a schedule
* @param data the name of the schedule to clear
*/
clearCourses: (data: { scheduleName: string }) => void;
/**
* Switches the active schedule to the one specified
* @param data the name of the schedule to switch to
*/
switchSchedule: (data: { scheduleName: string }) => void;
/**
* Creates a new schedule with the specified name
* @param data the name of the schedule to create
* @returns undefined if successful, otherwise an error message
*/
createSchedule: (data: { scheduleName: string }) => string | undefined;
/**
* Deletes a schedule with the specified name
* @param data the name of the schedule to delete
* @returns undefined if successful, otherwise an error message
*/
deleteSchedule: (data: { scheduleName: string }) => string | undefined;
/**
* Renames a schedule with the specified name
* @param data the name of the schedule to rename and the new name
* @returns undefined if successful, otherwise an error message
*/
renameSchedule: (data: { scheduleName: string; newName: string }) => string | undefined;
}

View File

@@ -14,7 +14,6 @@ export const UserScheduleStore = createLocalStore<IUserScheduleStore>({
new UserSchedule({
courses: [],
name: 'Schedule 1',
creditHours: 0,
}),
],
activeIndex: 0,

View File

@@ -7,11 +7,9 @@ import { Course } from './Course';
export class UserSchedule {
courses: Course[];
name: string;
creditHours: number;
constructor(schedule: Serialized<UserSchedule>) {
this.courses = schedule.courses.map(c => new Course(c));
this.creditHours = this.courses.reduce((acc, course) => acc + course.creditHours, 0);
this.name = schedule.name;
}