Files
overleaf-cep/services/web/frontend/js/shared/context/editor-context.js
Miguel Serrano 37d45d64b3 [ReactNavToolbar] Integration branch (#3513)
* Created ng-controller for react shared context and set editor.loading

* toolbar-header component with menu button (and story)

* Added editor-navigation-toolbar-root and react2angular plumbing

* Added eslint-disable exception to use <a/> instead of <button/>

* added 'menu' to extracted translation

* [ReactNavToolbar] Added cobranding and back to projects buttons (#3515)

GitOrigin-RevId: 27c3bba85cbc96a123d58c66a0bd5d6a2cfd8aca
2021-01-28 03:05:28 +00:00

43 lines
1.0 KiB
JavaScript

import React, { createContext, useContext } from 'react'
import PropTypes from 'prop-types'
export const EditorContext = createContext()
export function EditorProvider({ children, loading }) {
const cobranding = window.brandVariation
? {
logoImgUrl: window.brandVariation.logo_url,
brandVariationName: window.brandVariation.name,
brandVariationHomeUrl: window.brandVariation.home_url
}
: undefined
const ownerId =
window._ide.$scope.project && window._ide.$scope.project.owner
? window._ide.$scope.project.owner._id
: null
const editorContextValue = {
cobranding,
loading,
projectId: window.project_id,
isProjectOwner: ownerId === window.user.id
}
return (
<EditorContext.Provider value={editorContextValue}>
{children}
</EditorContext.Provider>
)
}
EditorProvider.propTypes = {
children: PropTypes.any,
loading: PropTypes.bool
}
export function useEditorContext() {
const editorContext = useContext(EditorContext)
return editorContext
}