mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 01:35:17 +01:00
42 lines
1015 B
JavaScript
42 lines
1015 B
JavaScript
import React, { useState, useEffect } from 'react';
|
|
import { get } from 'lib/web';
|
|
import WebsiteStats from './WebsiteStats';
|
|
import DateFilter from './DateFilter';
|
|
import { getDateRange } from '../lib/date';
|
|
|
|
export default function WebsiteList() {
|
|
const [data, setData] = useState();
|
|
const [dateRange, setDateRange] = useState(getDateRange('7d'));
|
|
const { startDate, endDate, unit } = dateRange;
|
|
|
|
async function loadData() {
|
|
setData(await get(`/api/website`));
|
|
}
|
|
|
|
function handleDateChange(value) {
|
|
setDateRange(value);
|
|
}
|
|
|
|
useEffect(() => {
|
|
loadData();
|
|
}, []);
|
|
|
|
return (
|
|
<div>
|
|
<DateFilter onChange={handleDateChange} />
|
|
{data &&
|
|
data.websites.map(({ website_id, label }) => (
|
|
<div key={website_id}>
|
|
<h2>{label}</h2>
|
|
<WebsiteStats
|
|
websiteId={website_id}
|
|
startDate={startDate}
|
|
endDate={endDate}
|
|
unit={unit}
|
|
/>
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|