mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-15 14:40:59 -05:00
9e72d55ea6
Make selecting a file update the file tree reliably in React IDE page GitOrigin-RevId: a59ccc53371ee22d577b0de70abad4ffbe7f5398
25 lines
717 B
TypeScript
25 lines
717 B
TypeScript
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
|
import { useCallback } from 'react'
|
|
import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
|
|
|
export function useSelectFileTreeEntity() {
|
|
const { fileTreeData, selectedEntities } = useFileTreeData()
|
|
|
|
const selectEntity = useCallback(
|
|
id => {
|
|
if (
|
|
selectedEntities.length === 1 &&
|
|
selectedEntities[0].entity._id === id
|
|
) {
|
|
return
|
|
}
|
|
const entityToSelect = findInTree(fileTreeData, id)
|
|
if (entityToSelect) {
|
|
window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: id }))
|
|
}
|
|
},
|
|
[fileTreeData, selectedEntities]
|
|
)
|
|
|
|
return { selectEntity }
|
|
}
|