@samitouri / QOSami-HFS / commits / bf365d41

admin/fs: auto-expand a single child at root level

Massimo Melina committed Mar 11, 2025 at 23:49 UTC bf365d41fc30b847a1ddb350b7b03310312b6251
1 file changed +8 -2
admin/src/VfsTree.ts
+8 -2
@@ -106,8 +106,14 @@ export default function VfsTree({ id2node, statusApi }:{ id2node: Map<string, Vf
106 }
107 }, [setExpanded])
108 const ref = useRef<HTMLUListElement>(null)
109 - const [expandAll, toggleBtn] = useToggleButton("Collapse all", "Expand all", exp => ({ icon: exp ? UnfoldLess : UnfoldMore, sx: { rotate: exp ? 0 : '180deg' } }))
110 - useEffectOnce(() => setExpanded(expandAll ? Array.from(id2node.keys()) : ['/']), [expandAll])
109 + const [expandAll, toggleBtn] = useToggleButton("Collapse all", "Expand all", exp => ({
110 + icon: exp ? UnfoldLess : UnfoldMore,
111 + sx: { rotate: exp ? 0 : '180deg' },
112 + }))
113 + useEffectOnce(() => {
114 + setExpanded(expandAll ? Array.from(id2node.keys())
115 + : ['/', ...vfs?.children?.length === 1 ? [vfs.children[0].id] : []]) // in case there's only one child, expand that too
116 + }, [expandAll, Boolean(vfs)]) // vfs is undefined on first render, we want to be called again as soon as it is loaded first time and not at reloads
117 // be sure selected element is visible
118 const treeId = 'vfs'
119 const first = selectedFiles[0]