mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 13:49:00 +02:00
7c97f8ab6e
* Use new JSX runtime and update Babel Node target * Update .eslintrc * Remove React imports GitOrigin-RevId: 559de0267f8f2934c56a860ea8701bb522aa861a
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
import { createContext, useContext, useMemo } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
|
|
export const ApplicationContext = createContext()
|
|
|
|
ApplicationContext.Provider.propTypes = {
|
|
value: PropTypes.shape({
|
|
user: PropTypes.shape({
|
|
id: PropTypes.string.isRequired,
|
|
firstName: PropTypes.string,
|
|
lastName: PropTypes.string,
|
|
}),
|
|
gitBridgePublicBaseUrl: PropTypes.string.isRequired,
|
|
}),
|
|
}
|
|
|
|
export function ApplicationProvider({ children }) {
|
|
const value = useMemo(() => {
|
|
const value = {
|
|
gitBridgePublicBaseUrl: window.gitBridgePublicBaseUrl,
|
|
}
|
|
|
|
if (window.user.id) {
|
|
value.user = window.user
|
|
}
|
|
|
|
return value
|
|
}, [])
|
|
|
|
return (
|
|
<ApplicationContext.Provider value={value}>
|
|
{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
|
|
}
|