mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #15792 from overleaf/td-ide-page-select-in-file-tree
Make selecting a file update the file tree reliably in React IDE page GitOrigin-RevId: a59ccc53371ee22d577b0de70abad4ffbe7f5398
This commit is contained in:
parent
88e4da6e3d
commit
9e72d55ea6
2 changed files with 6 additions and 7 deletions
|
@ -6,16 +6,16 @@ import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
|||
export function useOpenFile() {
|
||||
const ide = useIdeContext()
|
||||
|
||||
const { fileTreeData, setSelectedEntities } = useFileTreeData()
|
||||
const { fileTreeData } = useFileTreeData()
|
||||
|
||||
const openFileWithId = useCallback(
|
||||
(id: string) => {
|
||||
const result = findInTree(fileTreeData, id)
|
||||
if (result?.type === 'fileRef') {
|
||||
setSelectedEntities(result)
|
||||
window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: id }))
|
||||
}
|
||||
},
|
||||
[fileTreeData, setSelectedEntities]
|
||||
[fileTreeData]
|
||||
)
|
||||
|
||||
// Expose BinaryFilesManager via ide object solely for the benefit of the file
|
||||
|
|
|
@ -3,8 +3,7 @@ import { useCallback } from 'react'
|
|||
import { findInTree } from '@/features/file-tree/util/find-in-tree'
|
||||
|
||||
export function useSelectFileTreeEntity() {
|
||||
const { fileTreeData, selectedEntities, setSelectedEntities } =
|
||||
useFileTreeData()
|
||||
const { fileTreeData, selectedEntities } = useFileTreeData()
|
||||
|
||||
const selectEntity = useCallback(
|
||||
id => {
|
||||
|
@ -16,10 +15,10 @@ export function useSelectFileTreeEntity() {
|
|||
}
|
||||
const entityToSelect = findInTree(fileTreeData, id)
|
||||
if (entityToSelect) {
|
||||
setSelectedEntities([entityToSelect])
|
||||
window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: id }))
|
||||
}
|
||||
},
|
||||
[fileTreeData, selectedEntities, setSelectedEntities]
|
||||
[fileTreeData, selectedEntities]
|
||||
)
|
||||
|
||||
return { selectEntity }
|
||||
|
|
Loading…
Reference in a new issue