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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user