2021-03-18 05:52:36 -04:00
|
|
|
import React, { createContext, useContext, useState } from 'react'
|
2020-11-26 09:22:30 -05:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
2021-03-18 05:52:36 -04:00
|
|
|
const FileTreeMainContext = createContext()
|
|
|
|
|
|
|
|
export function useFileTreeMainContext() {
|
|
|
|
const context = useContext(FileTreeMainContext)
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
throw new Error(
|
|
|
|
'useFileTreeMainContext is only available inside FileTreeMainProvider'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
export const FileTreeMainProvider = function({
|
|
|
|
projectId,
|
|
|
|
hasWritePermissions,
|
2021-03-24 06:06:56 -04:00
|
|
|
userHasFeature,
|
2021-03-18 05:52:36 -04:00
|
|
|
refProviders,
|
|
|
|
reindexReferences,
|
|
|
|
setRefProviderEnabled,
|
|
|
|
setStartedFreeTrial,
|
2020-11-26 09:22:30 -05:00
|
|
|
children
|
|
|
|
}) {
|
|
|
|
const [contextMenuCoords, setContextMenuCoords] = useState()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FileTreeMainContext.Provider
|
|
|
|
value={{
|
|
|
|
projectId,
|
|
|
|
hasWritePermissions,
|
2021-03-24 06:06:56 -04:00
|
|
|
userHasFeature,
|
2021-03-18 05:52:36 -04:00
|
|
|
refProviders,
|
|
|
|
reindexReferences,
|
|
|
|
setRefProviderEnabled,
|
|
|
|
setStartedFreeTrial,
|
2020-11-26 09:22:30 -05:00
|
|
|
contextMenuCoords,
|
|
|
|
setContextMenuCoords
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</FileTreeMainContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeMainProvider.propTypes = {
|
|
|
|
projectId: PropTypes.string.isRequired,
|
|
|
|
hasWritePermissions: PropTypes.bool.isRequired,
|
2021-03-24 06:06:56 -04:00
|
|
|
userHasFeature: PropTypes.func.isRequired,
|
2021-03-18 05:52:36 -04:00
|
|
|
reindexReferences: PropTypes.func.isRequired,
|
|
|
|
refProviders: PropTypes.object.isRequired,
|
|
|
|
setRefProviderEnabled: PropTypes.func.isRequired,
|
|
|
|
setStartedFreeTrial: PropTypes.func.isRequired,
|
2020-11-26 09:22:30 -05:00
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
|
|
|
PropTypes.node
|
|
|
|
]).isRequired
|
|
|
|
}
|