On smaller screens we want the nav menu to be disabled by default

This commit is contained in:
Jackson Harper
2024-07-11 08:59:34 +08:00
parent 99633c15d5
commit a7e640320c
2 changed files with 8 additions and 0 deletions

View File

@ -4,10 +4,12 @@ export function usePersistedState<T>({
key,
initialValue,
isSessionStorage,
defaultEvaluator,
}: {
key: string
initialValue: T
isSessionStorage?: boolean
defaultEvaluator?: () => T
}): [T, (x: T | ((prev: T) => T)) => void, boolean] {
// State to store our value
// Pass initial state function to useState so logic is only executed once
@ -27,6 +29,8 @@ export function usePersistedState<T>({
// Parse stored json or if none return initialValue
if (item) {
setStoredValue(JSON.parse(item))
} else if (defaultEvaluator) {
setValue(defaultEvaluator())
}
setIsLoading(false)
} catch (error) {

View File

@ -9,6 +9,7 @@ import { LibraryContainer } from '../../components/templates/library/LibraryCont
import { useMemo } from 'react'
import { HighlightsContainer } from '../../components/nav-containers/HighlightsContainer'
import { usePersistedState } from '../../lib/hooks/usePersistedState'
import { isTouchScreenDevice } from '../../lib/deviceType'
export default function Home(): JSX.Element {
const router = useRouter()
@ -19,6 +20,9 @@ export default function Home(): JSX.Element {
key: 'nav-show-menu',
isSessionStorage: false,
initialValue: true,
defaultEvaluator: () => {
return !isTouchScreenDevice()
},
})
const section: NavigationSection | undefined = useMemo(() => {