Skip to content

Commit

Permalink
Fix dark-theme and share-button (#174)
Browse files Browse the repository at this point in the history
* persist the last theme chosen by the user

* fixed the way the 'share' function was getting the download url
  • Loading branch information
jandsonrj authored Aug 2, 2023
1 parent 9525d69 commit 422d85f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
6 changes: 5 additions & 1 deletion frontend/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
17 changes: 3 additions & 14 deletions frontend/components/ProductGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions frontend/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 422d85f

Please sign in to comment.