Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dark-theme and share-button #174

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading