refactoring courseschedule storage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Course } from '../types/Course';
|
||||
|
||||
export interface UserScheduleMessages {
|
||||
addCourse: (data: { scheduleId: string; course: Course }) => void;
|
||||
addCourse: (data: { scheduleName: string; course: Course }) => void;
|
||||
|
||||
removeCourse: (data: { scheduleId: string; course: Course }) => void;
|
||||
removeCourse: (data: { scheduleName: string; course: Course }) => void;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ interface IOptionsStore {
|
||||
shouldScrollToLoad: boolean;
|
||||
}
|
||||
|
||||
export const optionsStore = createSyncStore<IOptionsStore>({
|
||||
export const OptionsStore = createSyncStore<IOptionsStore>({
|
||||
shouldHighlightConflicts: true,
|
||||
shouldScrollToLoad: true,
|
||||
});
|
||||
|
||||
debugStore({ optionsStore });
|
||||
debugStore({ OptionsStore });
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { createLocalStore, debugStore } from 'chrome-extension-toolkit';
|
||||
import { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
interface IUserScheduleStore {
|
||||
schedules: UserSchedule[];
|
||||
activeIndex: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A store that is used for storing user schedules (and the active schedule)
|
||||
*/
|
||||
export const userScheduleStore = createLocalStore<IUserScheduleStore>({
|
||||
export const UserScheduleStore = createLocalStore<IUserScheduleStore>({
|
||||
schedules: [
|
||||
new UserSchedule({
|
||||
courses: [],
|
||||
id: uuidv4(),
|
||||
name: 'Schedule 1',
|
||||
creditHours: 0,
|
||||
}),
|
||||
],
|
||||
activeIndex: 0,
|
||||
});
|
||||
|
||||
debugStore({ userScheduleStore });
|
||||
debugStore({ userScheduleStore: UserScheduleStore });
|
||||
|
||||
@@ -6,14 +6,12 @@ import { Course } from './Course';
|
||||
*/
|
||||
export class UserSchedule {
|
||||
courses: Course[];
|
||||
id: string;
|
||||
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.id = schedule.id;
|
||||
this.name = schedule.name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user