// React/component imports import React, {useEffect, useState} from 'react'; import TimeSelector from './TimeSelector.js'; import Visualization from './Visualization.js'; import HubList from './HubList.js'; import Loading from './Loading.js'; import Modal from './Modal.js'; import logo from './images/logo.png'; // CSS import import '../css/App.css'; /** * Main component of the app. Holds the main layout of the big components. * @returns {import('react').HtmlHTMLAttributes} A div of the body of the page. */ function WatchDogs() { // State to open app when loaded const [hasLoaded, setHasLoaded] = useState(false); // State indicate if canvas is redrawing const [isChanging, setIsChanging] = useState(false); // State to hold dates -> two weeks apart on initialization. const [dates, setDates] = useState({ start: new Date(Date.now() - 12096e5), end: new Date() }); // State for visualization data const [data, setData] = useState([]); // State for selected person const [selected, setSelected] = useState(-1); const toEpochMilli = date => Date.parse(date); const getGraphData = () => { console.log({ start: toEpochMilli(dates.start), end: toEpochMilli(dates.end) }); fetch("http://localhost:4567/data", { method: "POST", body: JSON.stringify({ start: toEpochMilli(dates.start), end: toEpochMilli(dates.end) }), headers: { "Content-Type": "application/json", }, credentials: "same-origin" }) .then(res => res.json()) .then(data => { //TODO: optimize this const sliced = data.holders.slice(0, 500); console.log(sliced); setData(sliced); setHasLoaded(true); }) .catch(err => console.log(err)); setIsChanging(false); } // Hooks to update data on init and switching of data //useEffect(() => getGraphData(), []); useEffect(() => { setIsChanging(true); getGraphData(); }, [dates]); return ( <> {(!hasLoaded) ? :
PHP
} ); } export default WatchDogs;