* feat: use "copy of" for duplicated schedules and place them under the original schedule #358 * fix: code style and consistency
This commit is contained in:
@@ -10,15 +10,18 @@ import handleDuplicate from './handleDuplicate';
|
|||||||
*/
|
*/
|
||||||
export default async function duplicateSchedule(scheduleId: string): Promise<string | undefined> {
|
export default async function duplicateSchedule(scheduleId: string): Promise<string | undefined> {
|
||||||
const schedules = await UserScheduleStore.get('schedules');
|
const schedules = await UserScheduleStore.get('schedules');
|
||||||
const schedule = schedules.find(schedule => schedule.id === scheduleId);
|
const scheduleIndex = schedules.findIndex(schedule => schedule.id === scheduleId);
|
||||||
|
|
||||||
if (schedule === undefined) {
|
if (scheduleIndex === -1) {
|
||||||
throw new Error(`Schedule ${scheduleId} does not exist`);
|
throw new Error(`Schedule ${scheduleId} does not exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedName = await handleDuplicate(schedule.name);
|
const schedule = schedules[scheduleIndex]!;
|
||||||
|
|
||||||
schedules.push({
|
const copyOfName = `Copy of ${schedule.name}`;
|
||||||
|
const updatedName = await handleDuplicate(copyOfName);
|
||||||
|
|
||||||
|
schedules.splice(scheduleIndex + 1, 0, {
|
||||||
id: generateRandomId(),
|
id: generateRandomId(),
|
||||||
name: updatedName,
|
name: updatedName,
|
||||||
courses: JSON.parse(JSON.stringify(schedule.courses)),
|
courses: JSON.parse(JSON.stringify(schedule.courses)),
|
||||||
|
|||||||
Reference in New Issue
Block a user