From 422d85fd70e036c85f8a6fbc29c2edb85f8c98b2 Mon Sep 17 00:00:00 2001 From: Jandson Vitorino <101944851+jandsonrj@users.noreply.github.com> Date: Wed, 2 Aug 2023 12:32:34 -0300 Subject: [PATCH] Fix dark-theme and share-button (#174) * persist the last theme chosen by the user * fixed the way the 'share' function was getting the download url --- frontend/components/Header.js | 6 +++++- frontend/components/ProductGrid.js | 17 +++-------------- frontend/pages/_app.js | 5 +++++ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/frontend/components/Header.js b/frontend/components/Header.js index 6c0a992..9008bbb 100644 --- a/frontend/components/Header.js +++ b/frontend/components/Header.js @@ -73,7 +73,11 @@ function Header({ darkMode, setDarkMode }) { } const handleToggleDarkMode = () => { - setDarkMode(prevMode => !prevMode) + setDarkMode(prevMode => { + const newMode = !prevMode + localStorage.setItem('darkMode', newMode ? '1' : '0') + return newMode + }) } return ( diff --git a/frontend/components/ProductGrid.js b/frontend/components/ProductGrid.js index b334ea7..3b8efed 100644 --- a/frontend/components/ProductGrid.js +++ b/frontend/components/ProductGrid.js @@ -69,18 +69,6 @@ export default function ProductGrid(props) { }, []) const columns = React.useMemo(() => { - const getDownloadUrl = row => { - const { id, /* eslint-disable camelcase */ display_name } = row - - const formattedDisplayName = display_name - .replace(/[-\s]/g, '') - .toLowerCase() - - const productUrl = getProductUrl(`${id}_${formattedDisplayName}`) - const downloadUrl = `${window.location.origin}${productUrl}` - return downloadUrl - } - const handleDownload = row => { router.push(getProductUrl(row.internal_name)) } @@ -90,8 +78,9 @@ export default function ProductGrid(props) { } const handleShare = row => { - const downloadUrl = getDownloadUrl(row) - setSelectedFileUrl(downloadUrl) + const productUrl = getProductUrl(row.internal_name) + const shareUrl = `${window.location.origin}${productUrl}` + setSelectedFileUrl(shareUrl) setSnackbarOpen(true) } diff --git a/frontend/pages/_app.js b/frontend/pages/_app.js index 279e032..58bfd92 100644 --- a/frontend/pages/_app.js +++ b/frontend/pages/_app.js @@ -22,6 +22,11 @@ export default function MyApp(props) { if (jssStyles) { jssStyles.parentElement.removeChild(jssStyles) } + + const darkModePreference = localStorage.getItem('darkMode') + if (darkModePreference) { + setDarkMode(darkModePreference === '1') + } }, []) const light = createTheme({