feat: course color generation (#179)

* 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>
This commit is contained in:
Razboy20
2024-03-19 18:54:11 -05:00
committed by GitHub
parent c5fc6219e1
commit 5ed81e4be9
30 changed files with 424 additions and 422 deletions

View File

@@ -1,5 +1,6 @@
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.
@@ -15,6 +16,7 @@ export default async function addCourse(scheduleId: string, course: Course): Pro
throw new Error('Schedule not found');
}
course.colors = getUnusedColor(activeSchedule, course);
activeSchedule.courses.push(course);
activeSchedule.updatedAt = Date.now();

View File

@@ -14,10 +14,10 @@ export default async function deleteSchedule(scheduleId: string): Promise<string
const scheduleIndex = schedules.findIndex(schedule => schedule.id === scheduleId);
if (scheduleIndex === -1) {
return `Schedule ${scheduleId} does not exist`;
throw new Error(`Schedule ${scheduleId} does not exist`);
}
if (scheduleIndex === activeIndex) {
return 'Cannot delete active schedule';
throw new Error('Cannot delete active schedule');
}
schedules.splice(scheduleIndex, 1);

View File

@@ -17,7 +17,7 @@ export default async function renameSchedule(scheduleId: string, newName: string
// }
schedules[scheduleIndex].name = newName;
schedules[scheduleIndex].updatedAt = Date.now();
// schedules[scheduleIndex].updatedAt = Date.now();
await UserScheduleStore.set('schedules', schedules);
return undefined;