Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/icssc/peterportal-client in…
Browse files Browse the repository at this point in the history
…to merge-course-popovers

update from main
  • Loading branch information
CadenLee2 committed Jan 11, 2025
2 parents e0e2c05 + aecd5d1 commit 025aa9e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions site/src/pages/RoadmapPage/RoadmapMultiplan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface RoadmapSelectableItemProps {
index: number;
clickHandler: () => void;
editHandler: () => void;
duplicateHandler: () => void;
deleteHandler: () => void;
}

Expand All @@ -28,6 +29,7 @@ const RoadmapSelectableItem: FC<RoadmapSelectableItemProps> = ({
index,
clickHandler,
editHandler,
duplicateHandler,
deleteHandler,
}) => {
return (
Expand All @@ -38,6 +40,9 @@ const RoadmapSelectableItem: FC<RoadmapSelectableItemProps> = ({
<Button onClick={editHandler}>
<Icon.PencilFill width="16" height="16" />
</Button>
<Button onClick={duplicateHandler}>
<Icon.Files width="16" height="16" />
</Button>
<Button onClick={deleteHandler}>
<Icon.TrashFill width="16" height="16" />
</Button>
Expand Down Expand Up @@ -89,6 +94,24 @@ const RoadmapMultiplan: FC = () => {
setEditIdx(-1);
};

const duplicatePlan = (plan: RoadmapPlan) => {
let newName = `${plan.name} (Copy)`;
let counter = 1;
while (allPlans.plans.find((p) => p.name === newName)) {
counter++;
newName = `${plan.name} (Copy ${counter})`;
}
dispatch(
addRoadmapPlan({
name: newName,
content: JSON.parse(JSON.stringify(plan.content)),
}),
);
const newIndex = allPlans.plans.length;
setCurrentPlanIndex(newIndex);
dispatch(setPlanIndex(newIndex));
};

useEffect(() => {
document.title = `${name} | PeterPortal`;
}, [name]);
Expand Down Expand Up @@ -121,6 +144,7 @@ const RoadmapMultiplan: FC = () => {
setCurrentPlanIndex(index);
}}
editHandler={() => setEditIdx(index)}
duplicateHandler={() => duplicatePlan(plan)}
deleteHandler={() => setDelIdx(index)}
/>
))}
Expand Down

0 comments on commit 025aa9e

Please sign in to comment.