Website components. Update chart component.

This commit is contained in:
Mike Cao 2020-07-28 01:17:45 -07:00
parent d81ee3932d
commit bdcdcd9d13
9 changed files with 165 additions and 43 deletions

View file

@ -4,11 +4,11 @@ import { useAuth } from 'lib/middleware';
export default async (req, res) => {
await useAuth(req, res);
const { id, start_at, end_at, tz } = req.query;
const { id, start_at, end_at, unit, tz } = req.query;
const [pageviews, uniques] = await Promise.all([
getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, 'day', '*'),
getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, 'day', 'distinct session_id'),
getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, unit, '*'),
getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, unit, 'distinct session_id'),
]);
res.status(200).json({ pageviews, uniques });

View file

@ -2,9 +2,10 @@ import React from 'react';
import Link from 'next/link';
import { parse } from 'cookie';
import Layout from 'components/Layout';
import Chart from 'components/Chart';
import PageviewsChart from 'components/PageviewsChart';
import { verifySecureToken } from 'lib/crypto';
import { subDays, endOfDay } from 'date-fns';
import WebsiteList from '../components/WebsiteList';
export default function HomePage({ username }) {
return (
@ -12,8 +13,9 @@ export default function HomePage({ username }) {
<h2>
You've successfully logged in as <b>{username}</b>.
</h2>
<WebsiteList />
<div>
<Chart
<PageviewsChart
websiteId={3}
startDate={subDays(endOfDay(new Date()), 6)}
endDate={endOfDay(new Date())}