
This removes the useApp hook from all org pages in favor of various context. This means there is no longer global state that gets passed around, instead each component that requires access to something shared (like account, or navigation) can just use the context instead. This is a first step, as a lot of shared components stil rely on app not to mention the dev and lab sites.
37 lines
817 B
JavaScript
37 lines
817 B
JavaScript
import React, { useState, useContext } from 'react'
|
|
import { useNavigation } from 'site/hooks/use-navigation.mjs'
|
|
|
|
const defaultNavigationContext = {
|
|
path: [],
|
|
title: 'FIXME: No title (default)',
|
|
locale: 'en',
|
|
crumbs: [],
|
|
}
|
|
|
|
export const NavigationContext = React.createContext(defaultNavigationContext)
|
|
|
|
export const NavigationContextProvider = ({ children }) => {
|
|
function setNavigation(newValues) {
|
|
setValue({
|
|
...value,
|
|
...newValues,
|
|
setNavigation,
|
|
})
|
|
}
|
|
|
|
const [value, setValue] = useState({
|
|
...defaultNavigationContext,
|
|
setNavigation,
|
|
})
|
|
|
|
const navState = useNavigation({
|
|
path: value.path,
|
|
locale: value.locale,
|
|
})
|
|
|
|
return (
|
|
<NavigationContext.Provider value={{ ...value, ...navState }}>
|
|
{children}
|
|
</NavigationContext.Provider>
|
|
)
|
|
}
|