Skip to content

Commit

Permalink
fix: backup if a user has an invalid nav option
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Aug 29, 2024
1 parent fa81c87 commit 744ca90
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/components/popups/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ import { useStorage } from '@store/useStorage'
export function Navigation({ lat, lon, size = 'large' }) {
const nav = useStorage((s) => s.settings.navigation)
const url = useMemory((s) => s.settings.navigation[nav]?.url)

React.useEffect(() => {
const navOptions = useMemory.getState().settings.navigation
if (!url || !(nav in navOptions)) {
useStorage.setState((prev) => ({
settings: {
...prev.settings,
navigation: Object.keys(navOptions)[0],
},
}))
}
}, [url])

return (
<IconButton
href={url
.replaceAll('{x}', lat.toString())
.replaceAll('{y}', lon.toString())}
.replace(/\{x\}/g, lat.toString())
.replace(/\{y\}/g, lon.toString())}
target="_blank"
rel="noreferrer"
size={size}
Expand Down

0 comments on commit 744ca90

Please sign in to comment.