diff --git a/components/MetricCard.js b/components/MetricCard.js
index 4bce9960..4ebbe28a 100644
--- a/components/MetricCard.js
+++ b/components/MetricCard.js
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React from 'react';
import { useSpring, animated } from 'react-spring';
import styles from './MetricCard.module.css';
diff --git a/components/MetricCard.module.css b/components/MetricCard.module.css
index 0b3b945b..bfa692fb 100644
--- a/components/MetricCard.module.css
+++ b/components/MetricCard.module.css
@@ -8,6 +8,7 @@
.value {
font-size: 36px;
line-height: 40px;
+ min-height: 40px;
font-weight: 600;
}
diff --git a/components/PageviewsChart.module.css b/components/PageviewsChart.module.css
index 8e3636c9..e83e789a 100644
--- a/components/PageviewsChart.module.css
+++ b/components/PageviewsChart.module.css
@@ -19,6 +19,7 @@
width: 150px;
height: 50px;
transform: translate(-50%, -60px);
+ backdrop-filter: blur(4px);
}
.content:after {
@@ -52,5 +53,5 @@
height: 10px;
border-radius: 100%;
border: 1px solid #fff;
- margin-right: 10px;
+ margin-right: 8px;
}
diff --git a/components/QuickButtons.js b/components/QuickButtons.js
new file mode 100644
index 00000000..7ac77b12
--- /dev/null
+++ b/components/QuickButtons.js
@@ -0,0 +1,33 @@
+import React, { useState } from 'react';
+import classNames from 'classnames';
+import { getDateRange } from 'lib/date';
+import styles from './QuickButtons.module.css';
+
+const options = {
+ '24hour': '24h',
+ '7day': '7d',
+ '30day': '30d',
+};
+
+export default function QuickButtons({ onChange }) {
+ const [active, setActive] = useState('7day');
+
+ function handleClick(value) {
+ setActive(value);
+ onChange(getDateRange(value));
+ }
+
+ return (
+
+ {Object.keys(options).map(key => (
+
handleClick(key)}
+ >
+ {options[key]}
+
+ ))}
+
+ );
+}
diff --git a/components/QuickButtons.module.css b/components/QuickButtons.module.css
new file mode 100644
index 00000000..f0398be2
--- /dev/null
+++ b/components/QuickButtons.module.css
@@ -0,0 +1,20 @@
+.buttons {
+ display: flex;
+}
+
+.button {
+ font-size: 12px;
+ background: #f5f5f5;
+ padding: 4px 8px;
+ border-radius: 4px;
+ margin-right: 10px;
+ cursor: pointer;
+}
+
+.button:hover {
+ background: #eaeaea;
+}
+
+.active {
+ font-weight: 600;
+}
diff --git a/components/WebsiteList.js b/components/WebsiteList.js
index 27d91282..b6e3b5b8 100644
--- a/components/WebsiteList.js
+++ b/components/WebsiteList.js
@@ -2,39 +2,24 @@ import React, { useState, useEffect } from 'react';
import { get } from 'lib/web';
import WebsiteStats from './WebsiteStats';
import DateFilter from './DateFilter';
-import { getDateRange } from 'lib/date';
import styles from './WebsiteList.module.css';
export default function WebsiteList() {
const [data, setData] = useState();
- const [dateRange, setDateRange] = useState(getDateRange('7day'));
- const { startDate, endDate, unit } = dateRange;
async function loadData() {
setData(await get(`/api/website`));
}
- function handleDateChange(value) {
- setDateRange(value);
- }
-
useEffect(() => {
loadData();
}, []);
return (
-
{data &&
data.websites.map(({ website_id, label }) => (
-
+
))}
);
diff --git a/components/WebsiteStats.js b/components/WebsiteStats.js
index 8b5ef7a2..bf77a9bb 100644
--- a/components/WebsiteStats.js
+++ b/components/WebsiteStats.js
@@ -1,12 +1,16 @@
import React, { useState, useEffect, useMemo } from 'react';
import PageviewsChart from './PageviewsChart';
import { get } from 'lib/web';
-import { getDateArray, getTimezone } from 'lib/date';
+import { getDateArray, getDateRange, getTimezone } from 'lib/date';
import WebsiteSummary from './WebsiteSummary';
+import QuickButtons from './QuickButtons';
import styles from './WebsiteStats.module.css';
-export default function WebsiteStats({ title, websiteId, startDate, endDate, unit }) {
+export default function WebsiteStats({ title, websiteId }) {
const [data, setData] = useState();
+ const [dateRange, setDateRange] = useState(getDateRange('7day'));
+ const { startDate, endDate, unit } = dateRange;
+
const [pageviews, uniques] = useMemo(() => {
if (data) {
return [
@@ -17,6 +21,10 @@ export default function WebsiteStats({ title, websiteId, startDate, endDate, uni
return [[], []];
}, [data]);
+ function handleDateChange(values) {
+ setDateRange(values);
+ }
+
async function loadData() {
setData(
await get(`/api/website/${websiteId}/pageviews`, {
@@ -35,7 +43,10 @@ export default function WebsiteStats({ title, websiteId, startDate, endDate, uni
return (
);
diff --git a/components/WebsiteStats.module.css b/components/WebsiteStats.module.css
index a108a030..afdff3d5 100644
--- a/components/WebsiteStats.module.css
+++ b/components/WebsiteStats.module.css
@@ -8,3 +8,10 @@
line-height: 60px;
font-weight: 600;
}
+
+.header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 10px;
+}
diff --git a/lib/format.js b/lib/format.js
index c9480f31..c00f84d0 100644
--- a/lib/format.js
+++ b/lib/format.js
@@ -24,7 +24,7 @@ export function formatTime(val) {
}
export function formatShortTime(val, formats = ['m', 's'], space = '') {
- if (val === 0) {
+ if (val <= 0) {
return `0${formats[formats.length - 1]}`;
}
diff --git a/pages/index.js b/pages/index.js
index f99854d0..5d71fffa 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -10,9 +10,6 @@ import WebsiteList from '../components/WebsiteList';
export default function HomePage({ username }) {
return (
-
- You've successfully logged in as {username}.
-