Correct UI State

This commit is contained in:
Belen Curcio
2020-10-25 16:32:56 -03:00
parent 83725b3434
commit 42eb79d81f
5 changed files with 115 additions and 60 deletions

View File

@@ -5,11 +5,13 @@ import { SSRProvider, OverlayProvider } from 'react-aria'
export interface State {
displaySidebar: boolean
displayDropdown: boolean
displayModal: boolean
}
const initialState = {
displaySidebar: false,
displayDropdown: false,
displayModal: false,
}
type Action =
@@ -25,6 +27,12 @@ type Action =
| {
type: 'CLOSE_DROPDOWN'
}
| {
type: 'OPEN_MODAL'
}
| {
type: 'CLOSE_MODAL'
}
export const UIContext = React.createContext<State | any>(initialState)
@@ -56,6 +64,18 @@ function uiReducer(state: State, action: Action) {
displayDropdown: false,
}
}
case 'OPEN_MODAL': {
return {
...state,
displayModal: true,
}
}
case 'CLOSE_MODAL': {
return {
...state,
displayModal: false,
}
}
}
}
@@ -68,14 +88,21 @@ export const UIProvider: FC = (props) => {
const openDropdown = () => dispatch({ type: 'OPEN_DROPDOWN' })
const closeDropdown = () => dispatch({ type: 'CLOSE_DROPDOWN' })
const openModal = () => dispatch({ type: 'OPEN_MODAL' })
const closeModal = () => dispatch({ type: 'CLOSE_MODAL' })
const value = {
...state,
openSidebar,
closeSidebar,
openDropdown,
closeDropdown,
openModal,
closeModal,
}
console.log('state', state)
return <UIContext.Provider value={value} {...props} />
}