2020-12-14 06:44:10 -05:00
|
|
|
import React, { createContext, useContext } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2021-01-14 10:16:54 -05:00
|
|
|
import ExposedSettings from '../../main/exposed-settings'
|
2020-12-14 06:44:10 -05:00
|
|
|
|
|
|
|
export const ApplicationContext = createContext()
|
|
|
|
|
2021-02-10 05:36:41 -05:00
|
|
|
ApplicationContext.Provider.propTypes = {
|
|
|
|
value: PropTypes.shape({
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired
|
|
|
|
}),
|
|
|
|
exposedSettings: PropTypes.shape({
|
|
|
|
enableSubscriptions: PropTypes.bool
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-14 06:44:10 -05:00
|
|
|
export function ApplicationProvider({ children }) {
|
2021-01-14 10:16:54 -05:00
|
|
|
const applicationContextValue = {
|
|
|
|
user: window.user,
|
|
|
|
exposedSettings: ExposedSettings
|
|
|
|
}
|
2020-12-14 06:44:10 -05:00
|
|
|
return (
|
2021-01-14 10:16:54 -05:00
|
|
|
<ApplicationContext.Provider value={applicationContextValue}>
|
2020-12-14 06:44:10 -05:00
|
|
|
{children}
|
|
|
|
</ApplicationContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationProvider.propTypes = {
|
|
|
|
children: PropTypes.any
|
|
|
|
}
|
|
|
|
|
2021-02-10 05:36:41 -05:00
|
|
|
export function useApplicationContext(propTypes) {
|
|
|
|
const data = useContext(ApplicationContext)
|
|
|
|
PropTypes.checkPropTypes(
|
|
|
|
propTypes,
|
|
|
|
data,
|
|
|
|
'data',
|
|
|
|
'ApplicationContext.Provider'
|
|
|
|
)
|
|
|
|
return data
|
2020-12-14 06:44:10 -05:00
|
|
|
}
|