overleaf/services/web/frontend/js/shared/context/application-context.js
Miguel Serrano f9962fefe8 React git-bridge modal (#3869)
GitOrigin-RevId: 5b2609ed9ad7909a10cb08342053e955447688f5
2021-04-01 02:06:05 +00:00

46 lines
1.1 KiB
JavaScript

import React, { createContext, useContext } from 'react'
import PropTypes from 'prop-types'
import ExposedSettings from '../../main/exposed-settings'
export const ApplicationContext = createContext()
ApplicationContext.Provider.propTypes = {
value: PropTypes.shape({
user: PropTypes.shape({
id: PropTypes.string.isRequired
}),
exposedSettings: PropTypes.shape({
appName: PropTypes.string.isRequired,
enableSubscriptions: PropTypes.bool
}),
gitBridgePublicBaseUrl: PropTypes.string.isRequired
})
}
export function ApplicationProvider({ children }) {
const applicationContextValue = {
user: window.user,
exposedSettings: ExposedSettings,
gitBridgePublicBaseUrl: window.gitBridgePublicBaseUrl
}
return (
<ApplicationContext.Provider value={applicationContextValue}>
{children}
</ApplicationContext.Provider>
)
}
ApplicationProvider.propTypes = {
children: PropTypes.any
}
export function useApplicationContext(propTypes) {
const data = useContext(ApplicationContext)
PropTypes.checkPropTypes(
propTypes,
data,
'data',
'ApplicationContext.Provider'
)
return data
}