fix: 4th attempt for: now able to delete schedule even if active (#435)

* fix: 2nd attempt for: now able to delete schedule even if active

* fix: 3rd attempt for: now able to delete schedule even if active

* fix: 4th attempt for: now able to delete schedule even if active

---------

Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
This commit is contained in:
Long Phan
2025-01-02 12:31:41 -06:00
committed by GitHub
parent e61ab565c3
commit 24256798ba
2 changed files with 34 additions and 56 deletions

View File

@@ -18,20 +18,18 @@ export default async function deleteSchedule(scheduleId: string): Promise<string
if (scheduleIndex === -1) {
throw new Error(`Schedule ${scheduleId} does not exist`);
}
if (scheduleIndex === activeIndex) {
throw new Error(`Cannot delete active schedule`);
}
if (scheduleIndex < activeIndex) {
await UserScheduleStore.set('activeIndex', activeIndex - 1);
}
schedules.splice(scheduleIndex, 1);
await UserScheduleStore.set('schedules', schedules);
if (activeIndex >= schedules.length) {
await UserScheduleStore.set('activeIndex', schedules.length - 1);
let newActiveIndex = activeIndex;
if (scheduleIndex < activeIndex) {
newActiveIndex = activeIndex - 1;
} else if (activeIndex >= schedules.length) {
newActiveIndex = schedules.length - 1;
}
await UserScheduleStore.set('activeIndex', newActiveIndex);
return undefined;
}