From c5cb19a3bf162d0c889250ad72a1acd569e1db82 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Mon, 31 Aug 2020 14:11:30 -0700 Subject: [PATCH] Move date range selection into redux. --- components/WebsiteDetails.js | 48 ++++++---------------------- components/WebsiteList.js | 4 +-- components/common/DropDown.js | 6 ++-- components/common/RefreshButton.js | 15 +++++++-- components/metrics/BrowsersTable.js | 4 +-- components/metrics/CountriesTable.js | 11 +------ components/metrics/DevicesTable.js | 4 +-- components/metrics/EventsChart.js | 23 ++++++++----- components/metrics/EventsTable.js | 11 +------ components/metrics/MetricsBar.js | 20 +++++++++--- components/metrics/MetricsTable.js | 13 +++++--- components/metrics/OSTable.js | 4 +-- components/metrics/PagesTable.js | 11 +------ components/metrics/PageviewsChart.js | 5 ++- components/metrics/QuickButtons.js | 6 ++-- components/metrics/ReferrersTable.js | 13 ++------ components/metrics/WebsiteChart.js | 36 ++++++++++++--------- components/metrics/WebsiteHeader.js | 4 +-- hooks/useFetch.js | 4 +-- redux/actions/websites.js | 34 ++++++++++++++++++++ redux/reducers.js | 3 +- 21 files changed, 141 insertions(+), 138 deletions(-) create mode 100644 redux/actions/websites.js diff --git a/components/WebsiteDetails.js b/components/WebsiteDetails.js index 07f68ce8..bd8025ee 100644 --- a/components/WebsiteDetails.js +++ b/components/WebsiteDetails.js @@ -3,10 +3,8 @@ import classNames from 'classnames'; import WebsiteChart from 'components/metrics/WebsiteChart'; import WorldMap from 'components/common/WorldMap'; import Page from 'components/layout/Page'; -import WebsiteHeader from 'components/metrics/WebsiteHeader'; import MenuLayout from 'components/layout/MenuLayout'; import Button from 'components/common/Button'; -import { getDateRange } from 'lib/date'; import Arrow from 'assets/arrow-right.svg'; import styles from './WebsiteDetails.module.css'; import PagesTable from './metrics/PagesTable'; @@ -20,15 +18,12 @@ import EventsChart from './metrics/EventsChart'; import useFetch from 'hooks/useFetch'; import Loading from 'components/common/Loading'; -export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' }) { +export default function WebsiteDetails({ websiteId }) { + const { data } = useFetch(`/api/website/${websiteId}`); const [chartLoaded, setChartLoaded] = useState(false); const [countryData, setCountryData] = useState(); const [eventsData, setEventsData] = useState(); const [expand, setExpand] = useState(); - const [refresh, setRefresh] = useState(0); - const [dateRange, setDateRange] = useState(getDateRange(defaultDateRange)); - const { startDate, endDate, unit } = dateRange; - const { data } = useFetch(`/api/website/${websiteId}`); const BackButton = () => (