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

Feature/#117 bug new button #135

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>QuickMock</title>
</head>
<body>
<div id="root"></div>
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/canvas/canvas.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface SelectionInfo {
| Konva.KonvaEventObject<MouseEvent>
| Konva.KonvaEventObject<TouchEvent>
) => void;
clearSelection: () => void;
selectedShapeRef: React.MutableRefObject<Node<NodeConfig> | null>;
selectedShapeId: string;
selectedShapeType: ShapeType | null;
Expand Down
11 changes: 8 additions & 3 deletions src/core/providers/canvas/canvas.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ export const CanvasProvider: React.FC<Props> = props => {
const selectionInfo = useSelection(shapes, setShapes);

const deleteSelectedShape = () => {
setShapes(prevShapes =>
removeShapeFromList(selectionInfo.selectedShapeId, prevShapes)
);
setShapes(prevShapes => {
const newShapes = removeShapeFromList(
selectionInfo.selectedShapeId,
prevShapes
);
selectionInfo.clearSelection();
return newShapes;
});
};

const clearCanvas = () => {
Expand Down
8 changes: 8 additions & 0 deletions src/core/providers/canvas/use-selection.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const useSelection = (
}
};

const clearSelection = () => {
transformerRef.current?.nodes([]);
selectedShapeRef.current = null;
setSelectedShapeId('');
setSelectedShapeType(null);
};

const setZIndexOnSelected = (action: ZIndexAction) => {
setShapes(prevShapes =>
performZIndexAction(selectedShapeId, action, prevShapes)
Expand All @@ -64,6 +71,7 @@ export const useSelection = (
shapeRefs,
handleSelected,
handleClearSelection,
clearSelection,
selectedShapeRef,
selectedShapeId,
selectedShapeType,
Expand Down
3 changes: 2 additions & 1 deletion src/pods/toolbar/components/new-button/new-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import classes from '@/pods/toolbar/toolbar.pod.module.css';
import { useCanvasContext } from '@/core/providers';

export const NewButton = () => {
const { clearCanvas } = useCanvasContext();
const { clearCanvas, deleteSelectedShape } = useCanvasContext();

const handleClick = () => {
clearCanvas();
deleteSelectedShape();
};

return (
Expand Down
Loading