@@ -191,7 +191,14 @@ const LikeFilledIcon = styled(BsFillHeartFill)`
191191 cursor: pointer;
192192` ;
193193
194- const ShapeList = ( { setOpen, user, data, searchTerm } ) => {
194+ const ShapeList = (
195+ {
196+ setOpen,
197+ user,
198+ data,
199+ searchTerm,
200+ sort
201+ } ) => {
195202
196203 const filterShape = ( shapes , searchTerm ) => {
197204 if ( ! searchTerm ) {
@@ -209,8 +216,14 @@ const ShapeList = ({ setOpen, user, data, searchTerm }) => {
209216 const [ shapeToExport , setShapeToExport ] = useState ( ) ;
210217
211218 useEffect ( ( ) => {
212- setFilteredShape ( filterShape ( shapes , searchTerm ) ) ;
213- } , [ searchTerm , shapes ] ) ;
219+ const copy = [ ...shapes ] ;
220+ if ( sort === 'recent' ) {
221+ copy . sort ( ( a , b ) => b . __createdtime__ - a . __createdtime__ ) ;
222+ } else if ( sort === 'popularity' ) {
223+ copy . sort ( ( a , b ) => b . likes - a . likes ) ;
224+ }
225+ setFilteredShape ( filterShape ( copy , searchTerm ) ) ;
226+ } , [ searchTerm , shapes , sort ] ) ;
214227
215228 const handleSwicth = ( shapeName ) => {
216229
@@ -359,19 +372,18 @@ const ShapeList = ({ setOpen, user, data, searchTerm }) => {
359372 />
360373 < ShapeActions className = "shape-actions" >
361374 < ShapeActionsContainer >
362- < span
363- title = "Like"
375+ < span
364376 onClick = { ( event , shapeId ) => performLike ( event , shape [ 'shape_id' ] ) } >
365377 {
366378 shape . liked ?
367379 (
368- < Button variant = "danger" className = "btn-icon" >
380+ < Button title = "Remove Like" variant = "danger" className = "btn-icon" >
369381 < LikeFilledIcon size = { 24 } />
370382 </ Button >
371383 )
372384 :
373385 (
374- < Button variant = "outline-light" className = "btn-icon" >
386+ < Button title = "Add Like" variant = "outline-light" className = "btn-icon" >
375387 < LikeIcon size = { 24 } />
376388 </ Button >
377389 )
0 commit comments