mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #15581 from overleaf/td-ide-page-restore-file
React IDE page: implement file restore and simplify some state GitOrigin-RevId: ff63eb4f649156b58d9f8c4573cb6bd5b516a299
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user