Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2439 | Rev 2441 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from "react";
import { useEffect, useState } from "react";
import { axios } from "../../../utils";

const PeopleViewedHelper = (props) => {
  // props destructuring
  const { profileId } = props;

  // states
  const [peopleViewedProfile, setPeopleViewedProfile] = useState([]);
  const [lookMore, setLookMore] = useState(false);

  useEffect(() => {
    axios
      .get(`/helpers/people-viewed-profile/${profileId}`)
      .then((response) => {
        const resData = response.data;
        (resData);
        if (resData.success) {
          setPeopleViewedProfile(resData.data);
        } else {
          // alert error
        }
      });
  }, []);

  const getData = () => {
    let infoFollows = [...peopleViewedProfile]
    if (!lookMore) {
      infoFollows = infoFollows.slice(0, 5);
    }
    return infoFollows
  }

  return (
    <div className="right-sidebar border-radius border-gray p-3" style={{ maxHeight: '450px' }}>
      <div className="sd-title">
        <h3>Quién ha visto este perfil</h3>
      </div>
      <div
        className="mb-2"
        id="suggestions-similar-groups"
        style={{ height: "80%", overflowY: "auto" }}
      >
        {peopleViewedProfile.length
          ?
          getData().map(({ id, name, image, profile }) => (
            <div className="suggestion-usd" key={id}>
              <div className="row">
                <div className="col-md-4 col-sm-12" >
                  <img
                    style={{ width: "50px", height: "auto" }}
                    src={image}
                    alt=""
                  />
                </div>
                <div className="col-8 d-flex align-items-center justify-content-start p-0">
                  <div className="sgt-text">
                    <h4
                      className="cursor-pointer"
                      onClick={() => window.location.href = profile}
                    >
                      {name}
                    </h4>
                  </div>
                </div>
              </div>
            </div>
          ))
          : <div className="view-more">Sin sugerencias</div>
        }
      </div>
      {
        peopleViewedProfile.length >= 5
        &&
        <div className="w-100 text-center">
          <button className="btn btn-primary" onClick={() => setLookMore(!lookMore)}>
            {lookMore ? 'Ver menos' : 'Ver mas'}
          </button>
        </div>
      }
    </div>
  );
};

export default PeopleViewedHelper;