editor-context.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React, { createContext, useContext } from 'react'
  2. import PropTypes from 'prop-types'
  3. export const EditorContext = createContext()
  4. export function EditorProvider({ children, loading }) {
  5. const cobranding = window.brandVariation
  6. ? {
  7. logoImgUrl: window.brandVariation.logo_url,
  8. brandVariationName: window.brandVariation.name,
  9. brandVariationHomeUrl: window.brandVariation.home_url
  10. }
  11. : undefined
  12. const ownerId =
  13. window._ide.$scope.project && window._ide.$scope.project.owner
  14. ? window._ide.$scope.project.owner._id
  15. : null
  16. const editorContextValue = {
  17. cobranding,
  18. loading,
  19. projectId: window.project_id,
  20. isProjectOwner: ownerId === window.user.id
  21. }
  22. return (
  23. <EditorContext.Provider value={editorContextValue}>
  24. {children}
  25. </EditorContext.Provider>
  26. )
  27. }
  28. EditorProvider.propTypes = {
  29. children: PropTypes.any,
  30. loading: PropTypes.bool
  31. }
  32. export function useEditorContext() {
  33. const editorContext = useContext(EditorContext)
  34. return editorContext
  35. }