editor-context.js 738 B

12345678910111213141516171819202122232425262728293031
  1. import React, { createContext, useContext } from 'react'
  2. import PropTypes from 'prop-types'
  3. export const EditorContext = createContext()
  4. export function EditorProvider({ children }) {
  5. const ownerId =
  6. window._ide.$scope.project && window._ide.$scope.project.owner
  7. ? window._ide.$scope.project.owner._id
  8. : null
  9. const editorContextValue = {
  10. projectId: window.project_id,
  11. isProjectOwner: ownerId === window.user.id
  12. }
  13. return (
  14. <EditorContext.Provider value={editorContextValue}>
  15. {children}
  16. </EditorContext.Provider>
  17. )
  18. }
  19. EditorProvider.propTypes = {
  20. children: PropTypes.any
  21. }
  22. export function useEditorContext() {
  23. const editorContext = useContext(EditorContext)
  24. return editorContext
  25. }