Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4490 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4489 stevensc 1
/* eslint-disable react/prop-types */
2
import React, { useEffect, useState } from 'react'
3
import { axios } from '../../utils';
4
import EmptySection from '../empty-section/EmptySection';
5
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
6
 
7
const SuggestionWidget = ({ url, title }) => {
8
    const [suggestData, setSuggestData] = useState([]);
9
    const [lookMore, setLookMore] = useState(false);
10
 
11
    const getData = () => {
12
        axios.get(url)
13
            .then(({ data: response }) => {
14
                const { success, data } = response
15
                if (success) {
16
                    setSuggestData(data.sort((a, b) => a.priority - b.priority).reverse());
17
                }
18
            });
19
    }
20
 
21
    useEffect(() => {
22
        getData()
23
    }, []);
24
 
25
    const dataSlice = () => {
26
        let infoFollows = [...suggestData]
27
        if (!lookMore) {
28
            infoFollows = infoFollows.slice(0, 1)
29
        }
30
        return infoFollows
31
    }
32
 
33
    return (
34
        <div className='suggest__widget'>
35
            <div className="linked__widget-header">
36
                <h3>{title}</h3>
37
            </div>
38
            <div className='linked__widget-list'>
39
                {suggestData.length
40
                    ? dataSlice().map(({ id, name, image, profile }) => {
41
                        return (
42
                            <div className="linked__widget-content" key={id}>
43
                                <a href={profile} target="_blank" rel="noreferrer">
44
                                    <img src={image} alt={`${name} profile image`} />
45
                                </a>
46
                                <div className="linked__widget-info">
47
                                    <h4>{name}</h4>
48
                                    <a className='btn btn-primary' href={profile} target="_blank" rel="noreferrer">
49
                                        Ver perfil
50
                                    </a>
51
                                </div>
52
                            </div>
53
                        )
54
                    })
55
                    : <EmptySection message="Sin sugerencias" />
56
                }
57
            </div>
58
            <div className="load__suggest" onClick={()=> setLookMore(!lookMore)}>
59
                <span>{lookMore ? 'Ver menos' : 'Ver más'}</span>
60
                <ExpandMoreIcon className="ml-2" />
61
            </div>
62
        </div >
63
    )
64
}
65
 
66
export default SuggestionWidget