diff --git a/src/pages/background/lib/deleteSchedule.ts b/src/pages/background/lib/deleteSchedule.ts index 4455c3d7..d71b6164 100644 --- a/src/pages/background/lib/deleteSchedule.ts +++ b/src/pages/background/lib/deleteSchedule.ts @@ -18,20 +18,18 @@ export default async function deleteSchedule(scheduleId: string): Promise= 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; } diff --git a/src/views/components/common/ScheduleListItem.tsx b/src/views/components/common/ScheduleListItem.tsx index 82adcd9f..86e53e13 100644 --- a/src/views/components/common/ScheduleListItem.tsx +++ b/src/views/components/common/ScheduleListItem.tsx @@ -61,54 +61,34 @@ export default function ScheduleListItem({ schedule, dragHandleProps, onClick }: }; const handleDelete = () => { - if (schedule.id === activeSchedule.id) { - showDialog({ - title: `Unable to delete active schedule.`, - - description: ( - <> - Deleting the active schedule - {schedule.name} - is not allowed. Please switch to another schedule and try again. - - ), - // eslint-disable-next-line react/no-unstable-nested-components - buttons: close => ( - - ), - }); - } else { - showDialog({ - title: `Are you sure?`, - description: ( - <> - Deleting - {schedule.name} - is permanent and will remove all added courses from that schedule. - - ), - // eslint-disable-next-line react/no-unstable-nested-components - buttons: close => ( - <> - - - - ), - }); - } + + + ), + }); }; return (