mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 13:54:58 -05:00
4b86a54241
React IDE page: fix file preview with detached PDF and make PDF resizer toggler reattach PDF GitOrigin-RevId: e28bf753174fa445af70e5d3efae05f89aa5a21c
26 lines
845 B
TypeScript
26 lines
845 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, setSelectedEntities } = useFileTreeData()
|
|
|
|
const openFileWithId = useCallback(
|
|
(id: string) => {
|
|
const result = findInTree(fileTreeData, id)
|
|
if (result?.type === 'fileRef') {
|
|
setSelectedEntities(result)
|
|
}
|
|
},
|
|
[fileTreeData, setSelectedEntities]
|
|
)
|
|
|
|
// 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
|
|
}
|