11import React from 'react' ;
2- import { useDispatch } from 'react-redux' ;
2+ import { useSelector , useDispatch } from 'react-redux' ;
3+ import PropTypes from 'prop-types' ;
34
45import { uuid } from '../../utils/uuid' ;
56import { componentsActions } from '../../store/components' ;
@@ -9,15 +10,20 @@ import './components-picker.css'
910
1011export const ComponentsPicker = ( ) => {
1112 const dispatch = useDispatch ( ) ;
13+ const currentlyEdited = useSelector ( state => state . components ?. currentlyEdited ) ;
14+ const lockedPicker = Boolean ( currentlyEdited ) ;
15+
1216 const onComponentClick = layout => dispatch ( componentsActions . addComponent ( { id : uuid ( ) , layout} ) ) ;
1317
1418 return (
1519 < div className = "components-picker" >
1620 { AvailableComponents . map ( component => (
1721 < div
18- className = "components-picker__component"
22+ className = { `components-picker__component ${
23+ lockedPicker ? 'components-picker__component--disabled' : ''
24+ } `}
1925 key = { component . layout }
20- onClick = { ( ) => onComponentClick ( component . layout ) }
26+ onClick = { ! lockedPicker ? ( ) => onComponentClick ( component . layout ) : undefined }
2127 >
2228 < span className = "components-picker__component-label" >
2329 { component . label }
@@ -27,3 +33,7 @@ export const ComponentsPicker = () => {
2733 </ div >
2834 ) ;
2935}
36+
37+ ComponentsPicker . propTypes = {
38+ lockedPicker : PropTypes . bool . isRequired ,
39+ } ;
0 commit comments