mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
* rollup - fail when typescript has warnings or errors Currently this is detected when building the docu. Since the developer rarely does that the problem is detected on github. This change allows the developer to discover the error early by failing the build. * 3.0.75 * removed tw-elements * removed tw-elements package * found userType artefacts and removed it * fixed linting * 3.0.76 * adjust sidebar size and transition --------- Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
/* eslint-disable react/prop-types */
|
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
import { useCallback, useState, createContext, useContext } from 'react'
|
|
|
|
import type { AssetsApi } from '#types/AssetsApi'
|
|
|
|
interface AppState {
|
|
assetsApi: AssetsApi
|
|
sideBarOpen: boolean
|
|
sideBarSlim: boolean
|
|
}
|
|
|
|
type UseAppManagerResult = ReturnType<typeof useAppManager>
|
|
|
|
const initialAppState: AppState = {
|
|
assetsApi: {} as AssetsApi,
|
|
sideBarOpen: false,
|
|
sideBarSlim: false,
|
|
}
|
|
|
|
const AppContext = createContext<UseAppManagerResult>({
|
|
state: initialAppState,
|
|
setAppState: () => {},
|
|
})
|
|
|
|
function useAppManager(): {
|
|
state: AppState
|
|
setAppState: (newState: Partial<AppState>) => void
|
|
} {
|
|
const [state, setState] = useState<AppState>(initialAppState)
|
|
|
|
const setAppState = useCallback((newState: Partial<AppState>) => {
|
|
setState((prevState) => ({
|
|
...prevState,
|
|
...newState,
|
|
}))
|
|
}, [])
|
|
|
|
return { state, setAppState }
|
|
}
|
|
|
|
export const AppStateProvider: React.FunctionComponent<{
|
|
children?: React.ReactNode
|
|
}> = ({ children }) => <AppContext.Provider value={useAppManager()}>{children}</AppContext.Provider>
|
|
|
|
export const useAppState = (): AppState => {
|
|
const { state } = useContext(AppContext)
|
|
return state
|
|
}
|
|
|
|
export const useSetAppState = (): UseAppManagerResult['setAppState'] => {
|
|
const { setAppState } = useContext(AppContext)
|
|
return setAppState
|
|
}
|