@@ -33,13 +33,10 @@ export class Container extends Component {
3333 shapes : getAllShapes ( props . shapes ) ,
3434 } ;
3535 this . fakeImageHandler = {
36- cancel : ( ) => {
37- } ,
36+ cancel : ( ) => { } ,
3837 done : ( a , url ) => this . props . onImageUpload ( url ) ,
39- fileChosen : ( ) => {
40- } ,
41- progress : ( ) => {
42- }
38+ fileChosen : ( ) => { } ,
39+ progress : ( ) => { } ,
4340 } ;
4441 }
4542
@@ -55,7 +52,7 @@ export class Container extends Component {
5552 insertImage ( {
5653 ...this . fakeImageHandler ,
5754 getChosenFile : ( ) => file ,
58- isPasted : true
55+ isPasted : true ,
5956 } ) ;
6057 }
6158 }
@@ -108,23 +105,18 @@ export class Container extends Component {
108105
109106 onUpdateShapes = ( newShapes ) => {
110107 const { onUpdateShapes } = this . props ;
111-
112108 this . setState (
113109 { shapes : newShapes } ,
114110 // always transform shapes array back into shapes map when saving changes
115- ( ) => onUpdateShapes ( groupShapes ( newShapes ) )
111+ ( ) => onUpdateShapes ( groupShapes ( newShapes ) ) ,
116112 ) ;
117113 } ;
118114
119- handleUndo = ( ) => {
115+ onDeleteShape = ( id ) => {
120116 const { shapes } = this . state ;
121-
122117 if ( shapes && shapes . length ) {
123- // sort by index value
124- let newShapes = shapes . sort ( ( a , b ) => parseInt ( a . index ) - parseInt ( b . index ) ) ;
125-
126- newShapes = newShapes ? newShapes . slice ( 0 , newShapes . length - 1 ) : [ ] ;
127-
118+ // filter the deleted shape out
119+ let newShapes = shapes . filter ( ( shape ) => shape . id !== id ) ;
128120 this . onUpdateShapes ( newShapes ) ;
129121 }
130122 } ;
@@ -170,12 +162,12 @@ export class Container extends Component {
170162 } ) }
171163 { ...( dragEnabled
172164 ? {
173- onDragExit : this . handleOnDragExit ,
174- onDragLeave : this . handleOnDragExit ,
175- onDragOver : this . handleOnDragOver ,
176- onDrop : this . handleOnDrop ,
177- onPaste : this . handleOnPaste ,
178- }
165+ onDragExit : this . handleOnDragExit ,
166+ onDragLeave : this . handleOnDragExit ,
167+ onDragOver : this . handleOnDragOver ,
168+ onDrop : this . handleOnDrop ,
169+ onPaste : this . handleOnPaste ,
170+ }
179171 : { } ) }
180172 >
181173 < div className = { classes . toolbar } >
@@ -190,9 +182,7 @@ export class Container extends Component {
190182 } }
191183 />
192184 ) }
193-
194- < Button disabled = { ! ( shapes && shapes . length ) } onClick = { this . handleUndo } label = "Undo" />
195- < Button disabled = { ! ( shapes && shapes . length ) } onClick = { this . handleClearAll } label = "Clear all" />
185+ < Button disabled = { ! ( shapes && shapes . length ) } onClick = { this . handleClearAll } label = "Clear all" />
196186 </ div >
197187
198188 < div
@@ -211,6 +201,7 @@ export class Container extends Component {
211201 multipleCorrect = { multipleCorrect }
212202 onUpdateImageDimension = { onUpdateImageDimension }
213203 onUpdateShapes = { this . onUpdateShapes }
204+ onDeleteShape = { this . onDeleteShape }
214205 outlineColor = { outlineColor }
215206 shapes = { shapes }
216207 strokeWidth = { strokeWidth }
@@ -219,7 +210,7 @@ export class Container extends Component {
219210 ) : (
220211 < div className = { classNames ( classes . drawableHeight , classes . centered ) } >
221212 < label > Drag and drop or upload image from computer</ label >
222- < br />
213+ < br />
223214 < UploadControl
224215 label = "Upload Image"
225216 onInputClick = { this . handleInputClick }
@@ -238,11 +229,11 @@ export class Container extends Component {
238229 < label >
239230 Click and drag to create a hotspot. Click the hotspot to mark correct. Click again to unmark.
240231 </ label >
241- < div className = { classes . tooltipArrow } />
232+ < div className = { classes . tooltipArrow } />
242233 </ div >
243234 ) }
244235
245- < Help className = { classes . icon } onMouseOut = { this . toggleTooltip } onMouseOver = { this . toggleTooltip } />
236+ < Help className = { classes . icon } onMouseOut = { this . toggleTooltip } onMouseOver = { this . toggleTooltip } />
246237 </ div >
247238 ) }
248239 </ div >
0 commit comments