wip(new-design): Started work on standalon development environment
This commit is contained in:
parent
e908d419d5
commit
98ae9cc5ac
46 changed files with 1927 additions and 18 deletions
58
packages/new-design/shared/lab/hooks/useApp.js
Normal file
58
packages/new-design/shared/lab/hooks/useApp.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { useState } from 'react'
|
||||
// Stores state in local storage
|
||||
import useLocalStorage from 'shared/hooks/useLocalStorage.js'
|
||||
// Locale and translation
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTranslation } from 'next-i18next'
|
||||
import { capitalize } from 'shared/utils.mjs'
|
||||
import useTheme from 'shared/hooks/useTheme'
|
||||
|
||||
function useApp(full = true) {
|
||||
|
||||
// Load translation method
|
||||
const locale = useRouter().locale
|
||||
const { t } = useTranslation(['app'])
|
||||
|
||||
// Persistent state
|
||||
const [account, setAccount] = useLocalStorage('account', { username: false })
|
||||
const [theme, setTheme] = useTheme();
|
||||
|
||||
// React State
|
||||
const [primaryMenu, setPrimaryMenu] = useState(false)
|
||||
const [navigation, setNavigation] = useState({})
|
||||
const [slug, setSlug] = useState('/')
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
// State methods
|
||||
const togglePrimaryMenu = () => setPrimaryMenu(!primaryMenu)
|
||||
|
||||
return {
|
||||
// Static vars
|
||||
site: 'lab',
|
||||
|
||||
// i18n
|
||||
locale,
|
||||
|
||||
// State
|
||||
loading,
|
||||
navigation,
|
||||
primaryMenu,
|
||||
slug,
|
||||
theme,
|
||||
|
||||
// State setters
|
||||
setLoading,
|
||||
setNavigation,
|
||||
setPrimaryMenu,
|
||||
setSlug,
|
||||
setTheme,
|
||||
startLoading: () => { setLoading(true); setPrimaryMenu(false) }, // Always close menu when navigating
|
||||
stopLoading: () => setLoading(false),
|
||||
|
||||
// State handlers
|
||||
togglePrimaryMenu,
|
||||
}
|
||||
}
|
||||
|
||||
export default useApp
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue