// React import import { useEffect, useState } from "react"; // CSS import import "../css/UserCheckin.css"; import "../css/InvesterInfo.css"; import uuid from "react-uuid"; /** * Componenet for checkins. Has a toggle to show more info. * @param {Object} props The props of the component. * @returns {import('react').HtmlHTMLAttributes} A list element holding a checkin's info. */ function InvestorInfo(props) { const [info, setInfo] = useState({ percentGain: 0, percentSP500: 0, holdings: [] }); const [showStocks, setShowStocks] = useState(false); const [showFollowers, setShowFollowers] = useState(false); const getInfo = () => { if (props.selectedId === -1) { return; } const toEpochMilli = date => Date.parse(date); console.log({ selectedId: props.selectedId, startTime: toEpochMilli(props.dates.start), endTime: toEpochMilli(props.dates.end), }); fetch("http://localhost:4567/profit", { method: "POST", body: JSON.stringify({ selectedId: props.selectedId, startTime: toEpochMilli(props.dates.start), endTime: toEpochMilli(props.dates.end), }), headers: { "Content-Type": "application/json", }, credentials: "same-origin", }) .then(res => res.json()) .then(data => { console.log(data); setInfo(data); props.setShowSelectedInfo(true); }) .catch(err => console.log(err)); }; const stockTable = () => { return ( <>
  • Symbol
    Realized gain
    Unrealized gain
  • {info.holdings.map(holding =>
  • {holding.ticker}
    {holding.realizedGain.toFixed(3)}
    {holding.unrealizedGain.toFixed(3)}
  • )} ); }; const followerList = () => props.followers.map(follower =>
  • props.setSelectedId(follower.id)}>{follower.name}
  • ); // Hook that updates when selected has changed useEffect(() => getInfo(), [props.selectedId]); return ( ); } export default InvestorInfo;