2020-07-28 10:17:45 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { get } from 'lib/web';
|
|
|
|
import WebsiteStats from './WebsiteStats';
|
|
|
|
import DateFilter from './DateFilter';
|
2020-07-30 08:25:52 +02:00
|
|
|
import { getDateRange } from 'lib/date';
|
|
|
|
import styles from './WebsiteList.module.css';
|
2020-07-28 10:17:45 +02:00
|
|
|
|
|
|
|
export default function WebsiteList() {
|
|
|
|
const [data, setData] = useState();
|
2020-07-30 08:25:52 +02:00
|
|
|
const [dateRange, setDateRange] = useState(getDateRange('7day'));
|
2020-07-28 10:17:45 +02:00
|
|
|
const { startDate, endDate, unit } = dateRange;
|
|
|
|
|
|
|
|
async function loadData() {
|
|
|
|
setData(await get(`/api/website`));
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleDateChange(value) {
|
|
|
|
setDateRange(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loadData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2020-07-30 08:25:52 +02:00
|
|
|
<div className={styles.container}>
|
2020-07-28 10:17:45 +02:00
|
|
|
<DateFilter onChange={handleDateChange} />
|
|
|
|
{data &&
|
|
|
|
data.websites.map(({ website_id, label }) => (
|
2020-07-30 08:25:52 +02:00
|
|
|
<WebsiteStats
|
|
|
|
key={website_id}
|
|
|
|
title={label}
|
|
|
|
websiteId={website_id}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
|
|
|
unit={unit}
|
|
|
|
/>
|
2020-07-28 10:17:45 +02:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|