import React, { ChangeEvent, useContext, useState } from 'react' import DatePicker from 'react-datepicker' import { PageMarginLeftRight } from '../../style/PageMarginLeftRight' import styled, { ThemeContext } from 'styled-components' import { distance } from '../../style/sizes' import 'react-datepicker/dist/react-datepicker.css' import { InputWithLabel } from 'components/inputWithLabel/InputWithLabel' import Select from 'components/select/Select' import { ChartInfoBox } from 'components/chartInfoBox/ChartInfoBox' import Button from 'components/button/Button' import Input from 'components/input/Input' import { useHistory, useParams } from 'react-router' import { useEffect } from 'react' import { Bar, BarChart, CartesianGrid, Label, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' import { chartColors } from 'style/chartColors' import { ClipLoader } from 'react-spinners' interface IBikePointDetails { id: string, commonName: string, diagrammData: IBikePointActivityMap, installDate: number, nbDocks: number } type IBikePointActivityMap = {[hourOfDay: number]: IBikePointActivityAtHourOfDay} interface IBikePointActivityAtHourOfDay { avgNbRentals: number, avgNbReturns: number, avgNbTotal: number } /** * This page contains details about a specific bike point. */ export const BikePointDetails = () => { const history = useHistory() const { bikePointId } = useParams<{bikePointId: string}>() const [startTimeStamp, setStartTimestamp] = useState(Date.UTC(2015, 0, 4)) const [endTimeStamp, setEndTimeStamp] = useState(Date.UTC(2015, 0, 19)) const [dayOfWeek, setDayOfWeek] = useState(0) const [averageActivity, setAverageActivity] = useState('avgNbRentals') const [maxValueYAxis, setValueYAxis] = useState(0) // to be adjusted const [bikePointDetails, setBikePointDetails] = useState(undefined) const [loadingState, setLoadingState] = useState(false) useEffect(() => {fetchData()}, []) const fetchData = async () => { setLoadingState(true) const response = await fetch(`http://localhost:8081/api/bike-point-details/${bikePointId}?&from=${startTimeStamp / 1000}&to=${endTimeStamp / 1000}&day=${dayOfWeek}`) const jsonResponse = await response.json() //to be adjusted setBikePointDetails(jsonResponse.bikePointDetails) setLoadingState(false) } return ( history.push('/')}>Back home history.push('/map')}>Back to map

{bikePointDetails?.commonName ?? '...'}

ID:{bikePointDetails?.id ?? '...'} Install Date:{(bikePointDetails && new Date(bikePointDetails.installDate*1000).toDateString()) ?? '...'} Number of Docks:{bikePointDetails?.nbDocks ?? '...'}
setStartTimestamp(date.getTime())} dateFormat='yyyy/MM/dd' timeIntervals={5} customInput={} /> setEndTimeStamp(date.getTime())} dateFormat='yyyy/MM/dd' timeIntervals={5} customInput={} />    {loadingState && }
{ let value switch(averageActivity){ case 'avgNbRentals': value = entry[1].avgNbRentals if (value > maxValueYAxis) {setValueYAxis(value)} break case 'avgNbReturns': value = entry[1].avgNbReturns if (value > maxValueYAxis) {setValueYAxis(value)} break case 'avgNbTotal': value = entry[1].avgNbTotal if (value > maxValueYAxis) {setValueYAxis(value)} break } return { hourOfDay: entry[0], value: value?.toFixed(2) } })} margin={{top: 5, right: 0, left: 0, bottom: 20,}} barCategoryGap={15} >
) } const StyledRow = styled.div` padding: ${distance.large}; display: flex; flex-direction: row; ` const StyledMinWidth = styled.div` min-width: 10rem; ` const StyledTextRow = styled.div` padding-left: ${distance.large}; display: flex; flex-direction: row; ` const StyledButton = styled(Button)` margin-right: ${distance.large}; `