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({
|
2021-03-31 11:46:43 -04:00
|
|
|
appName: PropTypes.string.isRequired,
|
2021-02-10 05:36:41 -05:00
|
|
|
enableSubscriptions: PropTypes.bool
|
2021-03-31 11:46:43 -04:00
|
|
|
}),
|
|
|
|
gitBridgePublicBaseUrl: PropTypes.string.isRequired
|
2021-02-10 05:36:41 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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,
|
2021-03-31 11:46:43 -04:00
|
|
|
exposedSettings: ExposedSettings,
|
|
|
|
gitBridgePublicBaseUrl: window.gitBridgePublicBaseUrl
|
2021-01-14 10:16:54 -05:00
|
|
|
}
|
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
|
|
|
}
|