1- import React , { useState } from "react" ;
1+ import React , { useState , useEffect } from "react" ;
22
33// Bootstrap
44import Container from 'react-bootstrap/Container'
@@ -191,12 +191,27 @@ const LikeFilledIcon = styled(BsFillHeartFill)`
191191 cursor: pointer;
192192` ;
193193
194- const ShapeList = ( { setOpen, user, data } ) => {
194+ const ShapeList = ( { setOpen, user, data, searchTerm } ) => {
195+
196+ const filterShape = ( shapes , searchTerm ) => {
197+ if ( ! searchTerm ) {
198+ return shapes ;
199+ }
200+ return shapes . filter ( ( shape ) => {
201+ const shapeName = shape . name . toLowerCase ( ) ;
202+ return shapeName . includes ( searchTerm . toLowerCase ( ) ) ;
203+ } )
204+ }
195205
196206 const [ shapes , setShapes ] = useState ( data ) ;
207+ const [ filteredShape , setFilteredShape ] = useState ( shapes ) ;
197208 const [ showExportModal , setShowExportModal ] = useState ( false ) ;
198209 const [ shapeToExport , setShapeToExport ] = useState ( ) ;
199210
211+ useEffect ( ( ) => {
212+ setFilteredShape ( filterShape ( shapes , searchTerm ) ) ;
213+ } , [ searchTerm , shapes ] ) ;
214+
200215 const handleSwicth = ( shapeName ) => {
201216
202217 let modifiedShapes = shapes . map ( ( shape , index ) => {
@@ -312,6 +327,7 @@ const ShapeList = ({ setOpen, user, data }) => {
312327 return shape ;
313328 } ) ;
314329 setShapes ( ...[ modifiedShapes ] ) ;
330+ //setData(...[modifiedShapes]);
315331 }
316332 } ;
317333
@@ -324,7 +340,7 @@ const ShapeList = ({ setOpen, user, data }) => {
324340 setShow = { setShowExportModal }
325341 shape = { shapeToExport } /> }
326342
327- { shapes . map ( ( shape , index ) => (
343+ { filteredShape . map ( ( shape , index ) => (
328344 < React . Fragment key = { index } >
329345 < ShapeCard >
330346 < ShapeCardBody >
0 commit comments