mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
9e72d55ea6
Make selecting a file update the file tree reliably in React IDE page GitOrigin-RevId: a59ccc53371ee22d577b0de70abad4ffbe7f5398
26 lines
847 B
TypeScript
26 lines
847 B
TypeScript
import { useIdeContext } from '@/shared/context/ide-context'
|
|
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 useOpenFile() {
|
|
const ide = useIdeContext()
|
|
|
|
const { fileTreeData } = useFileTreeData()
|
|
|
|
const openFileWithId = useCallback(
|
|
(id: string) => {
|
|
const result = findInTree(fileTreeData, id)
|
|
if (result?.type === 'fileRef') {
|
|
window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: id }))
|
|
}
|
|
},
|
|
[fileTreeData]
|
|
)
|
|
|
|
// Expose BinaryFilesManager via ide object solely for the benefit of the file
|
|
// restore feature in history. This can be removed once Angular is gone.
|
|
ide.binaryFilesManager = { openFileWithId }
|
|
|
|
return openFileWithId
|
|
}
|