Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
setup admin context
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jul 26, 2020
commit a2a1857e928df0fa2678455644c7c67fda7da4fe
35 changes: 35 additions & 0 deletions web-app/src/services/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react'

type Props = {
children: React.ReactElement
}

type State = {
adminMode: boolean
}

type Action = { type: 'ADMIN_MODE_ON' | 'ADMIN_MODE_OFF' }

const AdminContext = React.createContext<{ state: State; dispatch: (action: Action) => void }>({
state: { adminMode: false },
dispatch: () => {},
})

export const AdminProvider = (props: Props) => {
const [state, dispatch] = React.useReducer(
(state: State, action: Action) => {
switch (action.type) {
case 'ADMIN_MODE_ON':
return { ...state, adminMode: true }
case 'ADMIN_MODE_OFF':
return { ...state, adminMode: false }
default:
throw new Error()
}
},
{ adminMode: false },
)
return <AdminContext.Provider value={{ state, dispatch }}>{props.children}</AdminContext.Provider>
}

export const AdminConsumer = AdminContext.Consumer