wrote all course/schedule background messages with handlers
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ export const UserScheduleStore = createLocalStore<IUserScheduleStore>({
|
||||
new UserSchedule({
|
||||
courses: [],
|
||||
name: 'Schedule 1',
|
||||
creditHours: 0,
|
||||
}),
|
||||
],
|
||||
activeIndex: 0,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user