mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
* removed daisy from config * removed tw-elements artefact * removed comments from tailwind config * removed safelist * migrated to tailwind4 and daisyui5 * deleted tailwind.config.js which is not eeded anymore * 3.0.79 * version number * fixed broken layouts * more fixing * more layout fixing * tested theming * small fixes * adapt snapshots to changes * package.json: add unit test update script * more ui refactoring & theme controller * ui improvements * package-lock.json * fix linting * fixed tabs * fix linting * fixed typing --------- Co-authored-by: mahula <lenzmath@posteo.de>
61 lines
1.5 KiB
TypeScript
61 lines
1.5 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
|
|
showThemeControl: boolean
|
|
embedded: boolean
|
|
openCollectiveApiKey: string
|
|
}
|
|
|
|
type UseAppManagerResult = ReturnType<typeof useAppManager>
|
|
|
|
const initialAppState: AppState = {
|
|
assetsApi: {} as AssetsApi,
|
|
sideBarOpen: false,
|
|
sideBarSlim: false,
|
|
showThemeControl: false,
|
|
embedded: false,
|
|
openCollectiveApiKey: '',
|
|
}
|
|
|
|
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
|
|
}
|