// 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, moneyIn: 0, moneyOut: 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 ( <>
{(info.moneyOut - info.moneyIn).toFixed(3)}$
gain{info.percentGain.toFixed(3)}%
compared to {info.percentSP500.toFixed(3)}% on SP500