@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
2
2
import { Link } from "react-router-dom" ;
3
3
import '../DayPanels.less'
4
4
import { compileArduinoCode , handleCreatorSaveDay , handleSave } from "../helpers" ;
5
- import { message , Spin , Menu , Checkbox } from "antd" ;
5
+ import { message , Spin , Menu , Checkbox , Row , Col , Input } from "antd" ;
6
6
import { getSaves } from "../../../Utils/requests" ;
7
7
import CodeModal from "./CodeModal" ;
8
8
import VersionHistoryModal from "./VersionHistoryModal"
@@ -16,6 +16,7 @@ export default function BlocklyCanvasPanel(props) {
16
16
const [ studentToolbox , setStudentToolbox ] = useState ( [ ] ) ;
17
17
const [ lastSavedTime , setLastSavedTime ] = useState ( null ) ;
18
18
const [ lastAutoSave , setLastAutoSave ] = useState ( null ) ;
19
+ const [ searchFilter , setSearchFilter ] = useState ( '' ) ;
19
20
const { day, homePath, handleGoBack, isStudent, isMentor, isContentCreator, lessonName } = props ;
20
21
21
22
const workspaceRef = useRef ( null ) ;
@@ -137,7 +138,25 @@ export default function BlocklyCanvasPanel(props) {
137
138
}
138
139
}
139
140
140
- const handleToolboxSelection = ( blockName ) => {
141
+ const selectEntireToolbox = ( event ) => {
142
+
143
+ if ( event . target . checked ) {
144
+ let tempToolBox = [ ] ;
145
+ day && day . toolbox && day . toolbox . forEach (
146
+ ( [ category , blocks ] ) => {
147
+ blocks . filter ( block => block . name . includes ( searchFilter ) ) . forEach ( ( block ) => {
148
+ tempToolBox = [ ...tempToolBox , block . name ] ;
149
+ } )
150
+ }
151
+ )
152
+ setStudentToolbox ( tempToolBox ) ;
153
+ }
154
+ else {
155
+ setStudentToolbox ( [ ] ) ;
156
+ }
157
+ }
158
+
159
+ const handleToolboxSelection = ( event , blockName ) => {
141
160
let index = studentToolbox . indexOf ( blockName ) ;
142
161
if ( index > - 1 ) {
143
162
setStudentToolbox ( studentToolbox . filter ( item => item !== blockName ) ) ;
@@ -175,112 +194,149 @@ export default function BlocklyCanvasPanel(props) {
175
194
return (
176
195
177
196
< div id = 'horizontal-container' className = "flex flex-column" >
178
- < Spin tip = "Compiling Code Please Wait..." className = "compilePop" spinning = { selectedCompile } >
179
- < div id = 'top-container' className = "flex flex-column vertical-container" >
180
- < div id = 'description-container' className = "flex flex-row space-between card" >
181
- < div className = 'flex flex-row' >
182
- { homePath ? < Link id = 'link' to = { homePath } className = "flex flex-column" >
183
- < i className = "fa fa-home" />
184
- </ Link > : null }
185
- { handleGoBack ? < button onClick = { handleGoBack } id = 'link' className = "flex flex-column" >
186
- < i id = 'icon-btn' className = "fa fa-arrow-left" />
187
- </ button > : null }
188
- </ div >
189
- < div >
190
- { isStudent && lastSavedTime ?
191
- `Last changes saved ${ lastSavedTime } `
192
- : null
193
- }
194
- </ div >
195
- < div className = 'flex flex-row' >
196
- { isStudent ?
197
- < div className = 'flex flex-row' >
198
- < VersionHistoryModal
199
- saves = { saves }
200
- lastAutoSave = { lastAutoSave }
201
- defaultTemplate = { day }
202
- getFormattedDate = { getFormattedDate }
203
- loadSave = { loadSave }
204
- />
205
- < button onClick = { handleManualSave } id = 'link' className = "flex flex-column" >
206
- < i id = 'icon-btn' className = "fa fa-save" />
207
- </ button >
208
- </ div >
209
- : null
210
- }
211
- { isContentCreator ?
212
- < div className = 'flex flex-row' >
213
- < button onClick = { handleCreatorSave } id = 'link' className = "flex flex-column" >
214
- < i id = 'icon-btn' className = "fa fa-save" />
215
- </ button >
216
- </ div >
217
- : null }
218
- < div className = 'flex flex-row' >
219
- < button onClick = { handleUndo } id = 'link' className = "flex flex-column" >
220
- < i id = 'icon-btn' className = "fa fa-undo-alt"
221
- style = { workspaceRef . current ?
222
- workspaceRef . current . undoStack_ . length < 1 ?
223
- { color : 'grey' , cursor : 'default' } : null
224
- : null }
225
- />
226
- </ button >
227
- < button onClick = { handleRedo } id = 'link' className = "flex flex-column" >
228
- < i id = 'icon-btn' className = "fa fa-redo-alt"
229
- style = { workspaceRef . current ?
230
- workspaceRef . current . redoStack_ . length < 1 ?
231
- { color : 'grey' , cursor : 'default' } : null
232
- : null }
233
- />
234
- </ button >
235
- </ div >
236
- </ div >
237
- < div style = { { "width" : "10%" } } >
238
- < div id = 'action-btn-container' className = "flex space-between" >
239
- { ! isStudent ?
240
- < CodeModal
241
- title = { 'XML' }
242
- workspaceRef = { workspaceRef . current }
243
- setHover = { setHoverXml }
244
- hover = { hoverXml }
245
- />
246
- : null }
247
- < CodeModal
248
- title = { 'Arduino Code' }
249
- workspaceRef = { workspaceRef . current }
250
- setHover = { setHoverArduino }
251
- hover = { hoverArduino }
252
- />
253
- < i onClick = { ( ) => compileArduinoCode ( workspaceRef . current , setSelectedCompile , day , isStudent ) }
254
- className = "fas fa-upload hvr-info"
255
- onMouseEnter = { ( ) => setHoverCompile ( true ) }
256
- onMouseLeave = { ( ) => setHoverCompile ( false ) } />
257
-
258
- { hoverCompile && < div className = "popup ModalCompile" > Upload to Arduino</ div > }
259
- </ div >
260
- </ div >
261
- </ div >
262
- </ div >
263
- </ Spin >
197
+
264
198
< div className = 'flex flex-row' >
265
199
< div id = 'bottom-container' className = "flex flex-column vertical-container overflow-visible" >
266
- < div id = "section-header" >
267
- { lessonName ? lessonName : "Program your Arduino..." }
268
- </ div >
200
+ < Row >
201
+ < Col flex = "none" id = "section-header" >
202
+ { lessonName ? lessonName : "Program your Arduino..." }
203
+ </ Col >
204
+ < Col flex = "auto" >
205
+
206
+ < Spin tip = "Compiling Code Please Wait..." className = "compilePop" spinning = { selectedCompile } >
207
+
208
+ < Row align = 'middle' justify = 'end' id = 'description-container' >
209
+ < Col span = { 1 } >
210
+ < Row >
211
+ { homePath ?
212
+ < Col >
213
+ < Link id = 'link' to = { homePath } className = "flex flex-column" >
214
+ < i className = "fa fa-home" />
215
+ </ Link >
216
+ </ Col >
217
+ : null }
218
+ { handleGoBack ?
219
+ < Col >
220
+ < button onClick = { handleGoBack } id = 'link' className = "flex flex-column" >
221
+ < i id = 'icon-btn' className = "fa fa-arrow-left" />
222
+ </ button >
223
+ </ Col >
224
+ : null }
225
+ </ Row >
226
+ </ Col >
227
+ < Col flex = 'auto' />
228
+
229
+ < Col span = { 6 } >
230
+ { isStudent && lastSavedTime ?
231
+ `Last changes saved ${ lastSavedTime } `
232
+ : null
233
+ }
234
+ </ Col >
235
+ < Col span = { isStudent ? 8 : 5 } >
236
+ < Row >
237
+ { isStudent ?
238
+ < Col className = 'flex flex-row' >
239
+ < VersionHistoryModal
240
+ saves = { saves }
241
+ lastAutoSave = { lastAutoSave }
242
+ defaultTemplate = { day }
243
+ getFormattedDate = { getFormattedDate }
244
+ loadSave = { loadSave }
245
+ />
246
+ < button onClick = { handleManualSave } id = 'link' className = "flex flex-column" >
247
+ < i id = 'icon-btn' className = "fa fa-save" />
248
+ </ button >
249
+ </ Col >
250
+ : null
251
+ }
252
+ { isContentCreator ?
253
+ < Col className = 'flex flex-row' >
254
+ < button onClick = { handleCreatorSave } id = 'link' className = "flex flex-column" >
255
+ < i id = 'icon-btn' className = "fa fa-save" />
256
+ </ button >
257
+ </ Col >
258
+ : null }
259
+ < Col className = 'flex flex-row' >
260
+ < button onClick = { handleUndo } id = 'link' className = "flex flex-column" >
261
+ < i id = 'icon-btn' className = "fa fa-undo-alt"
262
+ style = { workspaceRef . current ?
263
+ workspaceRef . current . undoStack_ . length < 1 ?
264
+ { color : 'grey' , cursor : 'default' } : null
265
+ : null }
266
+ />
267
+ </ button >
268
+ < button onClick = { handleRedo } id = 'link' className = "flex flex-column" >
269
+ < i id = 'icon-btn' className = "fa fa-redo-alt"
270
+ style = { workspaceRef . current ?
271
+ workspaceRef . current . redoStack_ . length < 1 ?
272
+ { color : 'grey' , cursor : 'default' } : null
273
+ : null }
274
+ />
275
+ </ button >
276
+ </ Col >
277
+ </ Row >
278
+
279
+ </ Col >
280
+ < Col span = { isStudent ? 3 : 5 } >
281
+ < div id = 'action-btn-container' className = "flex space-around" >
282
+ { ! isStudent ?
283
+ < CodeModal
284
+ title = { 'XML' }
285
+ workspaceRef = { workspaceRef . current }
286
+ setHover = { setHoverXml }
287
+ hover = { hoverXml }
288
+ />
289
+ : null }
290
+ < CodeModal
291
+ title = { 'Arduino Code' }
292
+ workspaceRef = { workspaceRef . current }
293
+ setHover = { setHoverArduino }
294
+ hover = { hoverArduino }
295
+ />
296
+ < i onClick = { ( ) => compileArduinoCode ( workspaceRef . current , setSelectedCompile , day , isStudent ) }
297
+ className = "fas fa-upload hvr-info"
298
+ onMouseEnter = { ( ) => setHoverCompile ( true ) }
299
+ onMouseLeave = { ( ) => setHoverCompile ( false ) } />
300
+ { hoverCompile && < div className = "popup ModalCompile" > Upload to Arduino</ div > }
301
+ </ div >
302
+ </ Col >
303
+ </ Row >
304
+
305
+ </ Spin >
306
+ </ Col >
307
+ </ Row >
308
+
269
309
< div id = "blockly-canvas" />
270
310
</ div >
271
311
{ isContentCreator ?
272
312
< div id = 'side-container' >
273
313
Current Student Toolbox Selection
314
+
315
+ < Input
316
+ placeholder = "Search Block"
317
+ prefix = { < i className = "fa fa-search" /> }
318
+ onChange = { e => setSearchFilter ( e . target . value ) }
319
+ />
320
+
321
+ < Checkbox onClick = { selectEntireToolbox } >
322
+ Select All
323
+ </ Checkbox >
324
+
274
325
< Menu mode = "inline" >
326
+
275
327
{
276
328
// Maps out block categories
277
329
day && day . toolbox && day . toolbox . map ( ( [ category , blocks ] ) => (
278
330
< SubMenu key = { category } title = { category } >
279
331
{
280
- blocks . map ( ( block ) => {
332
+ //filter out blocks not in search term
333
+ blocks . filter ( block => block . name . includes ( searchFilter ) ) . map ( ( block ) => {
281
334
return (
282
335
< Menu . Item key = { block . name } >
283
- < Checkbox onClick = { e => handleToolboxSelection ( block . name ) } > { block . name } </ Checkbox >
336
+ < Checkbox
337
+ checked = { studentToolbox . indexOf ( block . name ) > - 1 ? true : false }
338
+ onClick = { e => handleToolboxSelection ( e , block . name ) }
339
+ > { block . name } </ Checkbox >
284
340
</ Menu . Item >
285
341
)
286
342
} )
0 commit comments