Skip to content

Commit

Permalink
updated useSelectionHook
Browse files Browse the repository at this point in the history
  • Loading branch information
brauliodiez committed Dec 8, 2024
1 parent 065da29 commit 2827827
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/core/providers/canvas/use-selection.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,39 +194,44 @@ export const useSelection = (
);
};

const updateOtherPropsOnSelectedMutlipleShapes = <K extends keyof OtherProps>(
key: K,
value: OtherProps[K]
) => {
setDocument(prevDocument =>
produce(prevDocument, draft => {
draft.pages[prevDocument.activePageIndex].shapes = draft.pages[
prevDocument.activePageIndex
].shapes.map(shape =>
selectedShapesIds.includes(shape.id)
? {
...shape,
otherProps: { ...shape.otherProps, [key]: value },
}
: shape
);
})
);
};

const updateOtherPropsOnSelected = <K extends keyof OtherProps>(
key: K,
value: OtherProps[K],
multipleSelection: boolean = false
) => {
if (!isPageIndexValid(document) || selectedShapesIds.length === 0) return;

// TODO: Right now applying this only to single selection
// in the future we could apply to all selected shapes
// BUT, we have to show only common shapes (pain in the neck)
// Only when selection is one
// Single selection case
if (selectedShapesIds.length === 1) {
const selectedShapeId = selectedShapesIds[0];
updateOtherPropsOnSelectedSingleShape(selectedShapeId, key, value);

return;
}

// Multiple selection case
if (multipleSelection) {
setDocument(prevDocument =>
produce(prevDocument, draft => {
draft.pages[prevDocument.activePageIndex].shapes = draft.pages[
prevDocument.activePageIndex
].shapes.map(shape =>
selectedShapesIds.includes(shape.id)
? {
...shape,
otherProps: { ...shape.otherProps, [key]: value },
}
: shape
);
})
);
updateOtherPropsOnSelectedMutlipleShapes(key, value);
}
};

Expand Down

0 comments on commit 2827827

Please sign in to comment.