* feat: course color generation * feat: add proper TS for hex colors * refactor: fix oklab and improve contrast ratios * fix: update HexColor type * refactor: update color switch point * refactor: color-related functions and types * fix: imports and TS issues * fix: imports and TS issues * chore: add no-restricted-syntax ForInStatement * chore(docs): add jsdoc --------- Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
25 lines
937 B
TypeScript
25 lines
937 B
TypeScript
import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
|
|
import type { Course } from '@shared/types/Course';
|
|
import { getUnusedColor } from '@shared/util/colors';
|
|
|
|
/**
|
|
* Adds a course to a user's schedule.
|
|
* @param scheduleId - The id of the schedule to add the course to.
|
|
* @param course - The course to add.
|
|
* @returns A promise that resolves to void.
|
|
* @throws An error if the schedule is not found.
|
|
*/
|
|
export default async function addCourse(scheduleId: string, course: Course): Promise<void> {
|
|
const schedules = await UserScheduleStore.get('schedules');
|
|
const activeSchedule = schedules.find(s => s.id === scheduleId);
|
|
if (!activeSchedule) {
|
|
throw new Error('Schedule not found');
|
|
}
|
|
|
|
course.colors = getUnusedColor(activeSchedule, course);
|
|
activeSchedule.courses.push(course);
|
|
activeSchedule.updatedAt = Date.now();
|
|
|
|
await UserScheduleStore.set('schedules', schedules);
|
|
}
|