overleaf/services/web/frontend/js/shared/context/application-context.js
Timothée Alby 0ecebefb0c Merge pull request #3804 from overleaf/msm-react-publish-button
[ReactNavigationToolbar] Submit button

GitOrigin-RevId: 9b40e09f001b44bd2f5035469f0d0c852fea7199
2021-04-20 02:10:19 +00:00

48 lines
1.2 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,
firstName: PropTypes.string,
lastName: PropTypes.string
}),
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
}