refactor: Replace Webpack with Vite (#53)
This commit is contained in:
20
src/pages/background/lib/deleteSchedule.ts
Normal file
20
src/pages/background/lib/deleteSchedule.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
|
||||
|
||||
export default async function deleteSchedule(scheduleName: string): Promise<string | undefined> {
|
||||
const [schedules, activeIndex] = await Promise.all([
|
||||
UserScheduleStore.get('schedules'),
|
||||
UserScheduleStore.get('activeIndex'),
|
||||
]);
|
||||
|
||||
const scheduleIndex = schedules.findIndex(schedule => schedule.name === scheduleName);
|
||||
if (scheduleIndex === -1) {
|
||||
return `Schedule ${scheduleName} does not exist`;
|
||||
}
|
||||
if (scheduleIndex === activeIndex) {
|
||||
return 'Cannot delete active schedule';
|
||||
}
|
||||
|
||||
schedules.splice(scheduleIndex, 1);
|
||||
await UserScheduleStore.set('schedules', schedules);
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user