mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-01 15:41:30 -05:00
66c55b0647
GitOrigin-RevId: 9af00459ec121a605b84809b349a0bc258896048
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { createContext, FC, useContext, useState } from 'react'
|
|
|
|
type ContextMenuCoords = { top: number; left: number }
|
|
|
|
const FileTreeMainContext = createContext<
|
|
| {
|
|
refProviders: object
|
|
setRefProviderEnabled: (provider: string, value: boolean) => void
|
|
setStartedFreeTrial: (value: boolean) => void
|
|
contextMenuCoords: ContextMenuCoords | null
|
|
setContextMenuCoords: (value: ContextMenuCoords | null) => void
|
|
}
|
|
| undefined
|
|
>(undefined)
|
|
|
|
export function useFileTreeMainContext() {
|
|
const context = useContext(FileTreeMainContext)
|
|
|
|
if (!context) {
|
|
throw new Error(
|
|
'useFileTreeMainContext is only available inside FileTreeMainProvider'
|
|
)
|
|
}
|
|
|
|
return context
|
|
}
|
|
|
|
export const FileTreeMainProvider: FC<{
|
|
refProviders: object
|
|
setRefProviderEnabled: (provider: string, value: boolean) => void
|
|
setStartedFreeTrial: (value: boolean) => void
|
|
}> = ({
|
|
refProviders,
|
|
setRefProviderEnabled,
|
|
setStartedFreeTrial,
|
|
children,
|
|
}) => {
|
|
const [contextMenuCoords, setContextMenuCoords] =
|
|
useState<ContextMenuCoords | null>(null)
|
|
|
|
return (
|
|
<FileTreeMainContext.Provider
|
|
value={{
|
|
refProviders,
|
|
setRefProviderEnabled,
|
|
setStartedFreeTrial,
|
|
contextMenuCoords,
|
|
setContextMenuCoords,
|
|
}}
|
|
>
|
|
{children}
|
|
</FileTreeMainContext.Provider>
|
|
)
|
|
}
|