2024-02-01 04:41:12 -05:00
|
|
|
import React, { memo, useCallback, useState } from 'react'
|
2023-10-26 04:57:00 -04:00
|
|
|
import { useUserContext } from '@/shared/context/user-context'
|
|
|
|
import { useReferencesContext } from '@/features/ide-react/context/references-context'
|
|
|
|
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
|
|
|
import { useConnectionContext } from '@/features/ide-react/context/connection-context'
|
|
|
|
import { RefProviders } from '../../../../../types/user'
|
2023-12-15 04:19:42 -05:00
|
|
|
import FileTreeRoot from '@/features/file-tree/components/file-tree-root'
|
|
|
|
import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context'
|
2023-10-26 04:57:00 -04:00
|
|
|
|
2024-02-01 04:41:12 -05:00
|
|
|
export const FileTree = memo(function FileTree() {
|
2023-10-26 04:57:00 -04:00
|
|
|
const user = useUserContext()
|
|
|
|
const { indexAllReferences } = useReferencesContext()
|
|
|
|
const { setStartedFreeTrial } = useIdeReactContext()
|
2024-01-03 06:12:50 -05:00
|
|
|
const { isConnected, connectionState } = useConnectionContext()
|
2023-12-15 04:19:42 -05:00
|
|
|
const { handleFileTreeInit, handleFileTreeSelect, handleFileTreeDelete } =
|
|
|
|
useFileTreeOpenContext()
|
2023-10-26 04:57:00 -04:00
|
|
|
|
|
|
|
const [refProviders, setRefProviders] = useState<RefProviders>(
|
|
|
|
() => user.refProviders || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
function reindexReferences() {
|
|
|
|
indexAllReferences(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
const setRefProviderEnabled = useCallback(
|
|
|
|
(provider: keyof RefProviders, value = true) => {
|
|
|
|
setRefProviders(refProviders => ({ ...refProviders, [provider]: value }))
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
2024-02-05 06:44:05 -05:00
|
|
|
<FileTreeRoot
|
|
|
|
refProviders={refProviders}
|
|
|
|
reindexReferences={reindexReferences}
|
|
|
|
setRefProviderEnabled={setRefProviderEnabled}
|
|
|
|
setStartedFreeTrial={setStartedFreeTrial}
|
|
|
|
isConnected={isConnected || connectionState.reconnectAt !== null}
|
|
|
|
onInit={handleFileTreeInit}
|
|
|
|
onSelect={handleFileTreeSelect}
|
|
|
|
onDelete={handleFileTreeDelete}
|
|
|
|
/>
|
2023-10-26 04:57:00 -04:00
|
|
|
)
|
2024-02-01 04:41:12 -05:00
|
|
|
})
|