mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
1be43911b4
Set Prettier's "trailingComma" setting to "es5" GitOrigin-RevId: 9f14150511929a855b27467ad17be6ab262fe5d5
48 lines
1.2 KiB
JavaScript
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
|
|
}
|