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({
|
2021-04-19 08:38:03 -04:00
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
firstName: PropTypes.string,
|
2021-04-27 03:52:58 -04:00
|
|
|
lastName: PropTypes.string,
|
2021-02-10 05:36:41 -05:00
|
|
|
}),
|
|
|
|
exposedSettings: PropTypes.shape({
|
2021-03-31 11:46:43 -04:00
|
|
|
appName: PropTypes.string.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
enableSubscriptions: PropTypes.bool,
|
2021-03-31 11:46:43 -04:00
|
|
|
}),
|
2021-04-27 03:52:58 -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,
|
2021-04-27 03:52:58 -04:00
|
|
|
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 = {
|
2021-04-27 03:52:58 -04:00
|
|
|
children: PropTypes.any,
|
2020-12-14 06:44:10 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|