refactor(UserSchedule): index by a unique id rather than name (#166)
* refactor(UserSchedule): index by a unique id rather than name * refactor: Update parameter names in schedule function jsdocs * refactor: change more instances of .name to .id * refactor: Fix typo in variable name and update references * refactor: Remove console.log statement * fix(chromatic): Update ScheduleListItem story * refactor: remove unused eslint rule
This commit is contained in:
@@ -3,18 +3,18 @@ import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
|
||||
/**
|
||||
* Deletes a schedule with the specified name.
|
||||
*
|
||||
* @param scheduleName - The name of the schedule to delete.
|
||||
* @param scheduleId - The id of the schedule to delete.
|
||||
* @returns A promise that resolves to a string if there is an error, or undefined if the schedule is deleted successfully.
|
||||
*/
|
||||
export default async function deleteSchedule(scheduleName: string): Promise<string | undefined> {
|
||||
export default async function deleteSchedule(scheduleId: string): Promise<string | undefined> {
|
||||
const [schedules, activeIndex] = await Promise.all([
|
||||
UserScheduleStore.get('schedules'),
|
||||
UserScheduleStore.get('activeIndex'),
|
||||
]);
|
||||
|
||||
const scheduleIndex = schedules.findIndex(schedule => schedule.name === scheduleName);
|
||||
const scheduleIndex = schedules.findIndex(schedule => schedule.id === scheduleId);
|
||||
if (scheduleIndex === -1) {
|
||||
return `Schedule ${scheduleName} does not exist`;
|
||||
return `Schedule ${scheduleId} does not exist`;
|
||||
}
|
||||
if (scheduleIndex === activeIndex) {
|
||||
return 'Cannot delete active schedule';
|
||||
|
||||
Reference in New Issue
Block a user