2020-12-14 06:44:10 -05:00
|
|
|
import React, { createContext, useContext } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
export const EditorContext = createContext()
|
|
|
|
|
|
|
|
export function EditorProvider({ children }) {
|
2021-01-14 10:16:54 -05:00
|
|
|
const ownerId =
|
|
|
|
window._ide.$scope.project && window._ide.$scope.project.owner
|
|
|
|
? window._ide.$scope.project.owner._id
|
|
|
|
: null
|
|
|
|
|
|
|
|
const editorContextValue = {
|
|
|
|
projectId: window.project_id,
|
|
|
|
isProjectOwner: ownerId === window.user.id
|
|
|
|
}
|
|
|
|
|
2020-12-14 06:44:10 -05:00
|
|
|
return (
|
2021-01-14 10:16:54 -05:00
|
|
|
<EditorContext.Provider value={editorContextValue}>
|
2020-12-14 06:44:10 -05:00
|
|
|
{children}
|
|
|
|
</EditorContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorProvider.propTypes = {
|
|
|
|
children: PropTypes.any
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useEditorContext() {
|
2021-01-14 10:16:54 -05:00
|
|
|
const editorContext = useContext(EditorContext)
|
|
|
|
return editorContext
|
2020-12-14 06:44:10 -05:00
|
|
|
}
|