Go to selection mode after adding a shape

This commit is contained in:
Christopher Chedeau 2020-01-01 21:01:40 -08:00
parent f8873dd56b
commit ab84b5a048

View File

@ -144,6 +144,12 @@ function setSelection(selection) {
}); });
} }
function clearSelection() {
elements.forEach(element => {
element.isSelected = false;
});
}
function App() { function App() {
const [draggingElement, setDraggingElement] = React.useState(null); const [draggingElement, setDraggingElement] = React.useState(null);
const [elementType, setElementType] = React.useState("selection"); const [elementType, setElementType] = React.useState("selection");
@ -188,7 +194,11 @@ function App() {
<input <input
type="radio" type="radio"
checked={elementType === type} checked={elementType === type}
onChange={() => setElementType(type)} onChange={() => {
setElementType(type);
clearSelection();
drawScene();
}}
/> />
{children} {children}
</label> </label>
@ -247,6 +257,7 @@ function App() {
elements.pop(); elements.pop();
setSelection(draggingElement); setSelection(draggingElement);
} }
setElementType("selection");
drawScene(); drawScene();
}} }}
onMouseMove={e => { onMouseMove={e => {