diff --git a/.eslintrc.json b/.eslintrc.json index bcc38cf8..99c7e132 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -36,7 +36,7 @@ ["store", "./store"], ["styles", "./styles"] ], - "extensions": [".ts", ".js", ".jsx", ".json"] + "extensions": [".ts", ".tsx", ".js", ".jsx", ".json"] } } }, diff --git a/components/layout/NavBar.module.css b/components/layout/NavBar.module.css index da042ff7..b0d546bd 100644 --- a/components/layout/NavBar.module.css +++ b/components/layout/NavBar.module.css @@ -5,7 +5,7 @@ align-items: center; height: 60px; background: var(--base75); - border-bottom: 2px solid var(--base300); + border-bottom: 1px solid var(--base300); padding: 0 20px; } diff --git a/components/metrics/BarChart.js b/components/metrics/BarChart.js index 65881e28..3065247a 100644 --- a/components/metrics/BarChart.js +++ b/components/metrics/BarChart.js @@ -52,7 +52,7 @@ export default function BarChart({ millisecond: 'T', second: 'pp', minute: 'p', - hour: 'h aaa', + hour: 'h:mm aaa - PP', day: 'PPPP', week: 'PPPP', month: 'LLLL yyyy', @@ -135,15 +135,13 @@ export default function BarChart({ }, }, }; - }, [animationDuration, renderTooltip, stacked, colors]); + }, [animationDuration, renderTooltip, stacked, colors, unit]); const createChart = () => { Chart.defaults.font.family = 'Inter'; const options = getOptions(); - onCreate(options); - chart.current = new Chart(canvas.current, { type: 'bar', data: { @@ -151,6 +149,8 @@ export default function BarChart({ }, options, }); + + onCreate(chart.current); }; const updateChart = () => { @@ -158,9 +158,11 @@ export default function BarChart({ chart.current.options = getOptions(); - onUpdate(chart.current); + chart.current.data.datasets = datasets; chart.current.update(); + + onUpdate(chart.current); }; useEffect(() => { diff --git a/components/metrics/EventsChart.js b/components/metrics/EventsChart.js index 6ccab9ab..1fc461bb 100644 --- a/components/metrics/EventsChart.js +++ b/components/metrics/EventsChart.js @@ -17,7 +17,7 @@ export default function EventsChart({ websiteId, className, token }) { query: { url, eventName }, } = usePageQuery(); - const { data, isLoading } = useQuery(['events', { websiteId, modified, eventName }], () => + const { data, isLoading } = useQuery(['events', websiteId, modified, eventName], () => get(`/websites/${websiteId}/events`, { startAt: +startDate, endAt: +endDate, @@ -33,12 +33,12 @@ export default function EventsChart({ websiteId, className, token }) { if (!data) return []; if (isLoading) return data; - const map = data.reduce((obj, { x, y }) => { + const map = data.reduce((obj, { x, t, y }) => { if (!obj[x]) { obj[x] = []; } - obj[x].push({ x, y }); + obj[x].push({ x: t, y }); return obj; }, {}); @@ -58,22 +58,12 @@ export default function EventsChart({ websiteId, className, token }) { borderWidth: 1, }; }); - }, [data, isLoading]); - - function handleUpdate(chart) { - chart.data.datasets = datasets; - - chart.update(); - } + }, [data, isLoading, startDate, endDate, unit]); if (isLoading) { return ; } - if (!data) { - return null; - } - return ( diff --git a/components/metrics/PageviewsChart.js b/components/metrics/PageviewsChart.js index 43349006..f9cf52b0 100644 --- a/components/metrics/PageviewsChart.js +++ b/components/metrics/PageviewsChart.js @@ -38,35 +38,24 @@ export default function PageviewsChart({ }; }, [theme]); - const handleUpdate = chart => { - const { - data: { datasets }, - } = chart; + const datasets = useMemo(() => { + if (!data) return []; - datasets[0].data = data.sessions; - datasets[0].label = formatMessage(labels.uniqueVisitors); - datasets[1].data = data.pageviews; - datasets[1].label = formatMessage(labels.pageViews); - }; - - if (!data) { - return null; - } - - const datasets = [ - { - label: formatMessage(labels.uniqueVisitors), - data: data.sessions, - borderWidth: 1, - ...colors.visitors, - }, - { - label: formatMessage(labels.pageViews), - data: data.pageviews, - borderWidth: 1, - ...colors.views, - }, - ]; + return [ + { + label: formatMessage(labels.uniqueVisitors), + data: data.sessions, + borderWidth: 1, + ...colors.visitors, + }, + { + label: formatMessage(labels.pageViews), + data: data.pageviews, + borderWidth: 1, + ...colors.views, + }, + ]; + }, [data]); return (
@@ -78,7 +67,6 @@ export default function PageviewsChart({ unit={unit} records={records} animationDuration={visible ? animationDuration : 0} - onUpdate={handleUpdate} loading={loading} />
diff --git a/components/pages/console/TestConsole.js b/components/pages/console/TestConsole.js index c7e41c62..391260e5 100644 --- a/components/pages/console/TestConsole.js +++ b/components/pages/console/TestConsole.js @@ -1,13 +1,13 @@ +import { Button, Column, Row } from 'react-basics'; +import Script from 'next/script'; +import Link from 'next/link'; +import { useRouter } from 'next/router'; import WebsiteSelect from 'components/input/WebsiteSelect'; import Page from 'components/layout/Page'; import PageHeader from 'components/layout/PageHeader'; import EventsChart from 'components/metrics/EventsChart'; import WebsiteChart from 'components/metrics/WebsiteChart'; import useApi from 'hooks/useApi'; -import Head from 'next/head'; -import Link from 'next/link'; -import { useRouter } from 'next/router'; -import { Button, Column, Row } from 'react-basics'; import styles from './TestConsole.module.css'; export default function TestConsole() { @@ -24,22 +24,23 @@ export default function TestConsole() { } function handleClick() { - window.umami('umami-default'); - window.umami.trackView('/page-view', 'https://www.google.com'); - window.umami.trackEvent('track-event-no-data'); - window.umami.trackEvent('track-event-with-data', { - test: 'test-data', - time: new Date(), - number: 1, - time2: new Date().toISOString(), - nested: { + window.umami.track({ url: '/page-view', referrer: 'https://www.google.com' }); + window.umami.track('track-event-no-data'); + window.umami.track('track-event-with-data', { + data: { test: 'test-data', + time: new Date(), number: 1, - object: { + time2: new Date().toISOString(), + nested: { test: 'test-data', + number: 1, + object: { + test: 'test-data', + }, }, + array: [1, 2, 3], }, - array: [1, 2, 3], }); } @@ -52,22 +53,17 @@ export default function TestConsole() { return ( - - {typeof window !== 'undefined' && website && ( -