2021-06-23 09:37:08 +00:00
|
|
|
import { createContext, useContext, useState } from 'react'
|
2020-11-26 14:22:30 +00:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
2021-03-18 09:52:36 +00: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 14:22:30 +00:00
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
export const FileTreeMainProvider = function ({
|
2021-03-18 09:52:36 +00:00
|
|
|
refProviders,
|
|
|
|
reindexReferences,
|
|
|
|
setRefProviderEnabled,
|
|
|
|
setStartedFreeTrial,
|
2021-04-27 07:52:58 +00:00
|
|
|
children,
|
2020-11-26 14:22:30 +00:00
|
|
|
}) {
|
|
|
|
const [contextMenuCoords, setContextMenuCoords] = useState()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FileTreeMainContext.Provider
|
|
|
|
value={{
|
2021-03-18 09:52:36 +00:00
|
|
|
refProviders,
|
|
|
|
reindexReferences,
|
|
|
|
setRefProviderEnabled,
|
|
|
|
setStartedFreeTrial,
|
2020-11-26 14:22:30 +00:00
|
|
|
contextMenuCoords,
|
2021-04-27 07:52:58 +00:00
|
|
|
setContextMenuCoords,
|
2020-11-26 14:22:30 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</FileTreeMainContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeMainProvider.propTypes = {
|
2021-03-18 09:52:36 +00:00
|
|
|
reindexReferences: PropTypes.func.isRequired,
|
|
|
|
refProviders: PropTypes.object.isRequired,
|
|
|
|
setRefProviderEnabled: PropTypes.func.isRequired,
|
|
|
|
setStartedFreeTrial: PropTypes.func.isRequired,
|
2020-11-26 14:22:30 +00:00
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
2021-04-27 07:52:58 +00:00
|
|
|
PropTypes.node,
|
|
|
|
]).isRequired,
|
2020-11-26 14:22:30 +00:00
|
|
|
}
|