mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 22:55:51 -05:00
23593f8650
* Defer script loading * Refactor loading * Wait for project:joined * Only mount IdePage once everything has connected * Add useConnectionState hook and comments * Remove placeholder components * Move props into EditorAndSidebar * Move props into MainLayout * Tidy editor and sidebar components * Lazy-load the symbol palette pane and separate the loading pane GitOrigin-RevId: 4b721a06d6aba0ae0ec91768e6a6e29cf15e2083
24 lines
822 B
TypeScript
24 lines
822 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 }
|
|
}
|