Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3609 | Rev 3892 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3286 stevensc 1
/* eslint-disable react/prop-types */
1 www 2
import React from "react";
3
import { useEffect, useState } from "react";
2248 stevensc 4
import { axios } from "../../../utils";
1 www 5
 
3609 stevensc 6
const SuggestedGroupsHelper = ({ suggestedClassname }) => {
1 www 7
 
8
  // states
9
  const [suggestedGroups, setSuggestedGroups] = useState([]);
1773 steven 10
  const [lookMore, setLookMore] = useState(false);
3506 stevensc 11
 
1 www 12
  useEffect(() => {
2950 stevensc 13
    const url = '/helpers/groups-suggestion'
2925 stevensc 14
 
2924 stevensc 15
    axios.get(url)
3506 stevensc 16
      .then(({ data }) =>
17
        data.success &&
18
        setSuggestedGroups(data.data.sort((a, b) => parseInt(a.priority) - parseInt(b.priority)).reverse())
19
      )
1 www 20
  }, []);
1773 steven 21
 
22
  const getData = () => {
23
    let infoFollows = [...suggestedGroups]
2248 stevensc 24
    if (!lookMore) {
2926 stevensc 25
      infoFollows = infoFollows.slice(0, 3);
1773 steven 26
    }
27
    return infoFollows
28
  }
1 www 29
  return (
3609 stevensc 30
    <div className={`${suggestedClassname} peopleYouMayKnow`}>
2931 stevensc 31
      <div className="sd-title d-flex align-items-center justify-content-between">
2926 stevensc 32
        <h3>Grupos:</h3>
3506 stevensc 33
        {suggestedGroups.length >= 3 &&
2926 stevensc 34
          <a
35
            href="#"
36
            onClick={(e) => {
37
              e.preventDefault()
38
              setLookMore(!lookMore)
39
            }}
40
          >
41
            {lookMore ? 'Ver menos' : 'Ver mas'}
42
          </a>
43
        }
2248 stevensc 44
      </div>
3837 stevensc 45
      <div className="suggest-list">
3506 stevensc 46
        {suggestedGroups.length
47
          ? getData().map(({ id, name, image, profile }) =>
48
            <div className='user' key={id}>
2925 stevensc 49
              <div className="w-100 d-flex align-items-center" style={{ gap: '.5rem' }}>
3286 stevensc 50
                <a href={profile} target="_blank" rel="noreferrer">
2925 stevensc 51
                  <img src={image} alt={`${name} profile image`} />
52
                </a>
53
                <h4>{name}</h4>
54
              </div>
2927 stevensc 55
              <div className="w-100 d-flex align-items-center justify-content-end" style={{ gap: '.5rem' }}>
2925 stevensc 56
                <a
57
                  className="btn btn-primary"
58
                  href={profile}
1 www 59
                >
3050 stevensc 60
                  Ver Grupo
2925 stevensc 61
                </a>
1 www 62
              </div>
63
            </div>
3506 stevensc 64
          )
65
          : <div className="view-more">Sin sugerencias</div>
66
        }
1 www 67
      </div>
2248 stevensc 68
    </div>
1 www 69
  );
70
};
71
 
72
export default SuggestedGroupsHelper;