feat: auto create empty schedule when deleted all schedules (#552)
* feat: enhance schedule deletion to create a new schedule if none remain * feat: set active index to new schedule if only one exists * chore: run lint * feat: enhance schedule deletion to create a new schedule if none remain * feat: set active index to new schedule if only one exists * chore: run lint * feat: reset schedules on update, refactor invariant to within deleteSchedule * chore: pnpm lint --------- Co-authored-by: Samuel Gunter <29130894+Samathingamajig@users.noreply.github.com> Co-authored-by: Samuel Gunter <sgunter@utexas.edu>
This commit is contained in:
@@ -22,6 +22,11 @@ export default async function deleteSchedule(scheduleId: string): Promise<string
|
||||
schedules.splice(scheduleIndex, 1);
|
||||
await UserScheduleStore.set('schedules', schedules);
|
||||
|
||||
// By invariant, there must always be at least one schedule
|
||||
if (schedules.length === 0) {
|
||||
createSchedule('Schedule 1');
|
||||
}
|
||||
|
||||
let newActiveIndex = activeIndex;
|
||||
if (scheduleIndex < activeIndex) {
|
||||
newActiveIndex = activeIndex - 1;
|
||||
|
||||
Reference in New Issue
Block a user