Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use "copy of" for duplicated schedules and place them under the original schedule #358 #397

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/pages/background/lib/duplicateSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import handleDuplicate from './handleDuplicate';
*/
export default async function duplicateSchedule(scheduleId: string): Promise<string | undefined> {
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`);
}

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(),
name: updatedName,
courses: JSON.parse(JSON.stringify(schedule.courses)),
Expand Down
Loading