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
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export const FileTreeMainProvider = function ({
|
2020-11-26 09:22:30 -05:00
|
|
|
projectId,
|
|
|
|
hasWritePermissions,
|
2021-03-24 06:06:56 -04:00
|
|
|
userHasFeature,
|
2021-03-18 05:52:36 -04:00
|
|
|
refProviders,
|
|
|
|
reindexReferences,
|
|
|
|
setRefProviderEnabled,
|
|
|
|
setStartedFreeTrial,
|
2021-04-27 03:52:58 -04:00
|
|
|
children,
|
2020-11-26 09:22:30 -05:00
|
|
|
}) {
|
|
|
|
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,
|
2021-04-27 03:52:58 -04:00
|
|
|
setContextMenuCoords,
|
2020-11-26 09:22:30 -05:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{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),
|
2021-04-27 03:52:58 -04:00
|
|
|
PropTypes.node,
|
|
|
|
]).isRequired,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|