From d06c0770192068287d38bdf780f175dc7e11aa02 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Mon, 31 Aug 2020 03:53:39 -0700 Subject: [PATCH] Refactor components. Add refresh button. --- assets/redo.svg | 1 + components/WebsiteDetails.js | 19 +++++++++-- components/WebsiteList.js | 6 ++-- components/common/RefreshButton.js | 7 ++++ components/metrics/BarChart.js | 12 +++++-- components/metrics/MetricsBar.js | 39 ++++++++++++---------- components/metrics/MetricsBar.module.css | 2 +- components/metrics/PageviewsChart.js | 5 +-- components/metrics/WebsiteHeader.js | 42 +++++++++++------------- hooks/useFetch.js | 2 +- package.json | 4 +-- yarn.lock | 2 +- 12 files changed, 85 insertions(+), 56 deletions(-) create mode 100644 assets/redo.svg create mode 100644 components/common/RefreshButton.js diff --git a/assets/redo.svg b/assets/redo.svg new file mode 100644 index 00000000..4544eb1d --- /dev/null +++ b/assets/redo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/components/WebsiteDetails.js b/components/WebsiteDetails.js index 61e740e5..07f68ce8 100644 --- a/components/WebsiteDetails.js +++ b/components/WebsiteDetails.js @@ -17,16 +17,18 @@ import DevicesTable from './metrics/DevicesTable'; import CountriesTable from './metrics/CountriesTable'; import EventsTable from './metrics/EventsTable'; import EventsChart from './metrics/EventsChart'; -import useFetch from '../hooks/useFetch'; +import useFetch from 'hooks/useFetch'; +import Loading from 'components/common/Loading'; export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' }) { 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}`, { websiteId }); + const { data } = useFetch(`/api/website/${websiteId}`); const BackButton = () => ( - )} + + + {showLink && ( + + )} + ); } diff --git a/hooks/useFetch.js b/hooks/useFetch.js index 9f14e45e..b9b36c0f 100644 --- a/hooks/useFetch.js +++ b/hooks/useFetch.js @@ -35,5 +35,5 @@ export default function useFetch(url, params = {}, options = {}) { } }, [url, ...keys, ...update]); - return { data, error }; + return { data, error, loadData }; } diff --git a/package.json b/package.json index 17b79794..80bf5f9c 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,7 @@ ], "**/*.css": [ "stylelint --fix", - "prettier --write", - "eslint" + "prettier --write" ] }, "husky": { @@ -53,6 +52,7 @@ "dotenv": "^8.2.0", "formik": "^2.1.5", "geolite2-redist": "^1.0.7", + "immer": "^7.0.8", "is-localhost-ip": "^1.4.0", "jose": "^1.28.0", "maxmind": "^4.1.4", diff --git a/yarn.lock b/yarn.lock index 588dd177..73f0d4d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4456,7 +4456,7 @@ ignore@^5.1.4, ignore@^5.1.8: resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57" integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw== -immer@^7.0.3: +immer@^7.0.3, immer@^7.0.8: version "7.0.8" resolved "https://registry.yarnpkg.com/immer/-/immer-7.0.8.tgz#41dcbc5669a76500d017bef3ad0d03ce0a1d7c1e" integrity sha512-XnpIN8PXBBaOD43U8Z17qg6RQiKQYGDGGCIbz1ixmLGwBkSWwmrmx5X7d+hTtXDM8ur7m5OdLE0PiO+y5RB3pw==