import React, { ChangeEvent, useContext, useEffect, useState } from 'react' import { useHistory } from 'react-router-dom' import DatePicker from 'react-datepicker' import { PageMarginLeftRight } from '../../style/PageMarginLeftRight' import styled, { ThemeContext } from 'styled-components' import { distance } from '../../style/sizes' import { Bar, BarChart, CartesianGrid, Label, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' import { chartColors } from '../../style/chartColors' import 'react-datepicker/dist/react-datepicker.css' import Input from '../../components/input/Input' import { InputWithLabel } from '../../components/inputWithLabel/InputWithLabel' import { ChartInfoBox } from '../../components/chartInfoBox/ChartInfoBox' import Button from '../../components/button/Button' import Select from 'components/select/Select' import { ClipLoader } from 'react-spinners' import logo from './../../pictures/SantanderCyclesLogo.png'; interface IBikeTripDurationCount { classLabel: string, count: number } /** * Landing page of our dashboard. * Contains non-map visualizations. * Also contains link to access bike sharing map of London. */ export const Home = () => { const history = useHistory() const [startTimeStamp, setStartTimestamp] = useState(Date.UTC(2015, 0, 4, 0, 5)) const [endTimeStamp, setEndTimeStamp] = useState(Date.UTC(2015, 0, 19, 0, 10)) const [classSize, setClassSize] = useState(300) const [tripDurationData, setTripDurationData] = useState(undefined) const [loadingState, setLoadingState] = useState(false) // fetch data from our server once at beginning, later only on button click useEffect(() => {fetchData()}, []) const fetchData = async () => { setLoadingState(true) const response = await fetch(`http://localhost:8081/api/bike-trip-durations?classSize=${classSize}&from=${startTimeStamp / 1000}&to=${endTimeStamp / 1000}`) const jsonResponse = await response.json() setTripDurationData(jsonResponse.bikeTripDurationCounts) setLoadingState(false) } return (
Logo

Bike-sharing in London

setStartTimestamp(date.getTime())} dateFormat='yyyy/MM/dd, HH:mm' showTimeSelect timeFormat='HH:mm' timeIntervals={5} customInput={} /> setEndTimeStamp(date.getTime())} dateFormat='yyyy/MM/dd, HH:mm' showTimeSelect timeFormat='HH:mm' timeIntervals={5} customInput={} />    {loadingState && }
) } const StyledRow = styled.div` padding: ${distance.large}; display: flex; flex-direction: row; ` const StyledTopRow = styled.div` display: flex; flex-direction: row; justify-content: space-between; padding: ${distance.large}; `