2024-02-05 06:44:05 -05:00
|
|
|
import { ComponentProps, FC, useRef, useState } from 'react'
|
2024-01-18 07:54:24 -05:00
|
|
|
import FileTreeContext from '@/features/file-tree/components/file-tree-context'
|
|
|
|
|
|
|
|
export const FileTreeProvider: FC<{
|
|
|
|
refProviders?: Record<string, boolean>
|
|
|
|
}> = ({ children, refProviders = {} }) => {
|
2024-02-05 06:44:05 -05:00
|
|
|
const [fileTreeContainer, setFileTreeContainer] =
|
|
|
|
useState<HTMLDivElement | null>(null)
|
|
|
|
|
2024-01-30 10:36:06 -05:00
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-18 07:54:24 -05:00
|
|
|
return (
|
2024-02-05 06:44:05 -05:00
|
|
|
<div ref={setFileTreeContainer}>
|
|
|
|
{fileTreeContainer && (
|
|
|
|
<FileTreeContext
|
|
|
|
refProviders={refProviders}
|
|
|
|
fileTreeContainer={fileTreeContainer}
|
|
|
|
{...propsRef.current}
|
|
|
|
>
|
|
|
|
<>{children}</>
|
|
|
|
</FileTreeContext>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-01-18 07:54:24 -05:00
|
|
|
)
|
|
|
|
}
|