diff --git a/src/core/providers/canvas/canvas.model.ts b/src/core/providers/canvas/canvas.model.ts index 3a6c1a4d..7ac10e84 100644 --- a/src/core/providers/canvas/canvas.model.ts +++ b/src/core/providers/canvas/canvas.model.ts @@ -23,6 +23,7 @@ export interface SelectionInfo { export interface CanvasContextModel { shapes: ShapeModel[]; scale: number; + clearCanvas: () => void; setScale: React.Dispatch>; addNewShape: (type: ShapeType, x: number, y: number) => void; updateShapeSizeAndPosition: (id: string, position: Coord, size: Size) => void; diff --git a/src/core/providers/canvas/canvas.provider.tsx b/src/core/providers/canvas/canvas.provider.tsx index 55952ea6..b30c5994 100644 --- a/src/core/providers/canvas/canvas.provider.tsx +++ b/src/core/providers/canvas/canvas.provider.tsx @@ -14,6 +14,11 @@ export const CanvasProvider: React.FC = props => { const [scale, setScale] = React.useState(1); const selectionInfo = useSelection(shapes, setShapes); + + const clearCanvas = () => { + setShapes([]); + }; + const addNewShape = (type: ShapeType, x: number, y: number) => { setShapes(shapes => [...shapes, createShape({ x, y }, type)]); }; @@ -42,6 +47,7 @@ export const CanvasProvider: React.FC = props => { shapes, scale, setScale, + clearCanvas, selectionInfo, addNewShape, updateShapeSizeAndPosition, diff --git a/src/pods/toolbar/components/new-button/new-button.tsx b/src/pods/toolbar/components/new-button/new-button.tsx index 6f2f0d22..87adb150 100644 --- a/src/pods/toolbar/components/new-button/new-button.tsx +++ b/src/pods/toolbar/components/new-button/new-button.tsx @@ -1,10 +1,13 @@ import { NewIcon } from '@/common/components/icons/new-button.components'; import ToolbarButton from '../toolbar-button/toolbar-button'; import classes from '@/pods/toolbar/toolbar.pod.module.css'; +import { useCanvasContext } from '@/core/providers'; export const NewButton = () => { + const { clearCanvas } = useCanvasContext(); + const handleClick = () => { - console.log('New'); + clearCanvas(); }; return (