fix: admin/fs: after you create a folder, scrolling position was not preserved
Massimo Melina committed
Nov 1, 2024 at 16:42 UTC
671d795b519e307db29f6310e5d9cfcd151e3c59
1 file changed
+5
-1
admin/src/VfsTree.ts
+5
-1
@@ -1,7 +1,7 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
import { state, useSnapState } from './state'
4
-import { createElement as h, ReactElement, useRef, useState } from 'react'
4
+import { createElement as h, ReactElement, useEffect, useRef, useState } from 'react'
5
import { TreeItem, TreeView } from '@mui/x-tree-view'
6
import { ChevronRight, ExpandMore, TheaterComedy, Folder, Home, Link, InsertDriveFileOutlined, Lock,
7
RemoveRedEye, Web, Upload, Cloud, Delete, HighlightOff } from '@mui/icons-material'
@@ -23,7 +23,11 @@ export default function VfsTree({ id2node, statusApi }:{ id2node: Map<string, Vf
23
const ref = useRef<HTMLUListElement>()
24
if (!vfs)
25
return null
26
+ // be sure selected element is visible
27
const treeId = 'vfs'
28
+ const first = selectedFiles[0]
29
+ useEffect(() => document.getElementById(`${treeId}-${first?.id}`)?.scrollIntoView({ block: 'center', behavior: 'instant' as any }),
30
+ [first])
31
return h(TreeView, {
32
// @ts-ignore the type declared on the lib doesn't seem to be compatible with useRef()
33
ref,