mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 05:49:11 -05:00
6dc7ced2df
GitOrigin-RevId: 5a62bed823b716a6e0d6d3aa57ee187d161f3346
35 lines
1 KiB
TypeScript
35 lines
1 KiB
TypeScript
import { ComponentProps, FC, useRef, useState } from 'react'
|
|
import FileTreeContext from '@/features/file-tree/components/file-tree-context'
|
|
|
|
export const FileTreeProvider: FC<{
|
|
refProviders?: Record<string, boolean>
|
|
}> = ({ children, refProviders = {} }) => {
|
|
const [fileTreeContainer, setFileTreeContainer] =
|
|
useState<HTMLDivElement | null>(null)
|
|
|
|
const propsRef =
|
|
useRef<Omit<ComponentProps<typeof FileTreeContext>, 'refProviders'>>()
|
|
|
|
if (propsRef.current === undefined) {
|
|
propsRef.current = {
|
|
reindexReferences: cy.stub().as('reindexReferences'),
|
|
setRefProviderEnabled: cy.stub().as('setRefProviderEnabled'),
|
|
setStartedFreeTrial: cy.stub().as('setStartedFreeTrial'),
|
|
onSelect: cy.stub(),
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div ref={setFileTreeContainer}>
|
|
{fileTreeContainer && (
|
|
<FileTreeContext
|
|
refProviders={refProviders}
|
|
fileTreeContainer={fileTreeContainer}
|
|
{...propsRef.current}
|
|
>
|
|
<>{children}</>
|
|
</FileTreeContext>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|