1
0
Fork 0

wip(org): Work on new site

This commit is contained in:
Joost De Cock 2022-05-25 18:35:20 +02:00
parent 66502c73c7
commit c934e44484
13 changed files with 607 additions and 40 deletions

View file

@ -2,13 +2,47 @@ import { useState } from 'react'
import set from 'lodash.set'
// Stores state in local storage
import useLocalStorage from 'shared/hooks/useLocalStorage.js'
// Translation
//import { en } from '@freesewing/i18n'
// Prebuild navigation
import prebuildNavigation from 'site/prebuild/navigation.js'
// Translation
import { useTranslation } from 'next-i18next'
/*
* Helper method for a simple navigation item
*/
const simpleNav = (term, t, lng, prefix='') => ({
__title: t(term, { lng }),
__linktitle: t(term, { lng }),
__slug: prefix+term,
__order: t(term, { lng })
})
/*
* Generated the static navigation
* Static means not mdx, not strapi
*/
const staticNavigation = (t, lang) => ({
designs: simpleNav('designs', t, lang),
community: simpleNav('community', t, lang),
account: simpleNav('account', t, lang),
})
/*
* Merges prebuild navigation with the static navigation
*/
const buildNavigation = (lang, t) => ({
...prebuildNavigation[lang],
...staticNavigation(t, lang),
})
/*
* The actual hook
*/
function useApp(full = true) {
// Load translation method
const { t } = useTranslation()
// User color scheme preference
const prefersDarkMode = (typeof window !== 'undefined' && typeof window.matchMedia === 'function')
? window.matchMedia(`(prefers-color-scheme: dark`).matches
@ -21,7 +55,7 @@ function useApp(full = true) {
// React State
const [primaryMenu, setPrimaryMenu] = useState(false)
const [navigation, setNavigation] = useState(prebuildNavigation[language])
const [navigation, setNavigation] = useState(buildNavigation(language, t))
const [slug, setSlug] = useState('/')
const [loading, setLoading] = useState(false)