@@ -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,16 @@ 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+ } else if ( sort === 'oldest' ) {
225+ copy . sort ( ( a , b ) => a . __createdtime__ - b . __createdtime__ ) ;
226+ }
227+ setFilteredShape ( filterShape ( copy , searchTerm ) ) ;
228+ } , [ searchTerm , shapes , sort ] ) ;
214229
215230 const handleSwicth = ( shapeName ) => {
216231
@@ -359,19 +374,18 @@ const ShapeList = ({ setOpen, user, data, searchTerm }) => {
359374 />
360375 < ShapeActions className = "shape-actions" >
361376 < ShapeActionsContainer >
362- < span
363- title = "Like"
377+ < span
364378 onClick = { ( event , shapeId ) => performLike ( event , shape [ 'shape_id' ] ) } >
365379 {
366380 shape . liked ?
367381 (
368- < Button variant = "danger" className = "btn-icon" >
382+ < Button title = "Remove Like" variant = "danger" className = "btn-icon" >
369383 < LikeFilledIcon size = { 24 } />
370384 </ Button >
371385 )
372386 :
373387 (
374- < Button variant = "outline-light" className = "btn-icon" >
388+ < Button title = "Add Like" variant = "outline-light" className = "btn-icon" >
375389 < LikeIcon size = { 24 } />
376390 </ Button >
377391 )
0 commit comments