From 24256798ba7b877dd170d77ce4970b13b8a69a68 Mon Sep 17 00:00:00 2001 From: Long Phan <75595656+Wizardbacon13@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:31:41 -0600 Subject: [PATCH] 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> --- src/pages/background/lib/deleteSchedule.ts | 16 ++-- .../components/common/ScheduleListItem.tsx | 74 +++++++------------ 2 files changed, 34 insertions(+), 56 deletions(-) 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 (