mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 05:11:34 +02:00
Skip opening root document if delete originated from a file-restore (#27992)
* Skip opening root document if delete originated from a file-restore * handle project-restore origin * Refactor isFileRestore logic GitOrigin-RevId: f2a34189140deb4e614d93e8d197b8a6a90c8f65
This commit is contained in:
committed by
Copybot
parent
b2df393bbb
commit
d82dcc382a
@@ -20,6 +20,7 @@ import { useDragLayer } from 'react-dnd'
|
||||
import classnames from 'classnames'
|
||||
import { pathInFolder } from '@/features/file-tree/util/path'
|
||||
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
|
||||
import { FileTreeFindResult } from '@/features/ide-react/types/file-tree'
|
||||
|
||||
const FileTreeRoot = React.memo<{
|
||||
onSelect: () => void
|
||||
@@ -115,7 +116,11 @@ const FileTreeRoot = React.memo<{
|
||||
)
|
||||
})
|
||||
|
||||
function FileTreeRootFolder({ onDelete }: { onDelete: () => void }) {
|
||||
function FileTreeRootFolder({
|
||||
onDelete,
|
||||
}: {
|
||||
onDelete: (entity: FileTreeFindResult, isFileRestore?: boolean) => void
|
||||
}) {
|
||||
useFileTreeSocketListener(onDelete)
|
||||
const { fileTreeData } = useFileTreeData()
|
||||
|
||||
|
||||
@@ -6,8 +6,11 @@ import { useFileTreeSelectable } from '../contexts/file-tree-selectable'
|
||||
import { findInTree, findInTreeOrThrow } from '../util/find-in-tree'
|
||||
import { useIdeContext } from '@/shared/context/ide-context'
|
||||
import { useSnapshotContext } from '@/features/ide-react/context/snapshot-context'
|
||||
import { FileTreeFindResult } from '@/features/ide-react/types/file-tree'
|
||||
|
||||
export function useFileTreeSocketListener(onDelete: (entity: any) => void) {
|
||||
export function useFileTreeSocketListener(
|
||||
onDelete: (entity: FileTreeFindResult, isFileRestore?: boolean) => void
|
||||
) {
|
||||
const user = useUserContext()
|
||||
const {
|
||||
dispatchRename,
|
||||
@@ -53,7 +56,10 @@ export function useFileTreeSocketListener(onDelete: (entity: any) => void) {
|
||||
|
||||
useEffect(() => {
|
||||
if (fileTreeFromHistory) return
|
||||
function handleDispatchDelete(entityId: string) {
|
||||
function handleDispatchDelete(
|
||||
entityId: string,
|
||||
origin?: { kind: string } | string
|
||||
) {
|
||||
const entity = findInTree(fileTreeData, entityId)
|
||||
unselect(entityId)
|
||||
if (selectedEntityParentIds.has(entityId)) {
|
||||
@@ -70,8 +76,12 @@ export function useFileTreeSocketListener(onDelete: (entity: any) => void) {
|
||||
}
|
||||
}
|
||||
dispatchDelete(entityId)
|
||||
if (onDelete) {
|
||||
onDelete(entity)
|
||||
if (onDelete && entity) {
|
||||
const isFileRestore =
|
||||
typeof origin === 'object' &&
|
||||
(origin.kind === 'file-restore' || origin.kind === 'project-restore')
|
||||
|
||||
onDelete(entity, isFileRestore)
|
||||
}
|
||||
}
|
||||
if (socket) socket.on('removeEntity', handleDispatchDelete)
|
||||
|
||||
@@ -121,10 +121,10 @@ export const FileTreeOpenProvider: FC<React.PropsWithChildren> = ({
|
||||
)
|
||||
|
||||
const handleFileTreeDelete = useCallback(
|
||||
(entity: FileTreeFindResult) => {
|
||||
(entity: FileTreeFindResult, isFileRestore?: boolean) => {
|
||||
eventEmitter.emit('entity:deleted', entity)
|
||||
// Select the root document if the current document was deleted
|
||||
if (entity.entity._id === currentDocumentId) {
|
||||
// Select the root document if the current document was deleted and delete is not part of a file restore
|
||||
if (!isFileRestore && entity.entity._id === currentDocumentId) {
|
||||
openDocWithId(rootDocId!)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user