import React, { useState } from 'react'; import classNames from 'classnames'; import MetricCard from './MetricCard'; import Loading from 'components/common/Loading'; import useFetch from 'hooks/useFetch'; import { formatShortTime, formatNumber, formatLongNumber } from 'lib/format'; import styles from './MetricsBar.module.css'; import { useDateRange } from '../../hooks/useDateRange'; export default function MetricsBar({ websiteId, className }) { const dateRange = useDateRange(websiteId); const { startDate, endDate, modified } = dateRange; const { data } = useFetch( `/api/website/${websiteId}/metrics`, { start_at: +startDate, end_at: +endDate, }, { update: [modified], }, ); const [format, setFormat] = useState(true); const formatFunc = format ? formatLongNumber : formatNumber; function handleSetFormat() { setFormat(state => !state); } const { pageviews, uniques, bounces, totaltime } = data || {}; return (