Website components. Update chart component.
This commit is contained in:
25
components/WebsiteStats.js
Normal file
25
components/WebsiteStats.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import PageviewsChart from './PageviewsChart';
|
||||
import { get } from 'lib/web';
|
||||
import { getTimezone } from 'lib/date';
|
||||
|
||||
export default function WebsiteStats({ websiteId, startDate, endDate, unit }) {
|
||||
const [data, setData] = useState();
|
||||
|
||||
async function loadData() {
|
||||
setData(
|
||||
await get(`/api/website/${websiteId}/pageviews`, {
|
||||
start_at: +startDate,
|
||||
end_at: +endDate,
|
||||
unit,
|
||||
tz: getTimezone(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, [websiteId, startDate, endDate]);
|
||||
|
||||
return <PageviewsChart data={data} />;
|
||||
}
|
||||
Reference in New Issue
Block a user