@samitouri / QOSami-HFS / commits / 279c1219

fix: admin/fs: after closing the form of a folder, adding an element wasn't done under the folder

Massimo Melina committed Jan 17, 2024 at 00:24 UTC 279c12199662ffe3bc74dce22967aebe39689244
2 files changed +10 -8
admin/src/VfsPage.ts
+7 -6
@@ -31,18 +31,19 @@ export default function VfsPage() {
31 const ret = status?.urls.https || status?.urls.http
32 return b && !ret.includes(b) ? [b, ...ret] : ret
33 }, [status])
34 + const [hideForm, setHideForm] = useState(false)
35
35 - function selectNone() {
36 - state.selectedFiles = []
36 + function closeForm() {
37 + setHideForm(true)
38 }
39
39 - const sideContent = !selectedFiles.length ? null
40 + const sideContent = !selectedFiles.length || hideForm ? null
41 : selectedFiles.length === 1 ? h(FileForm, {
42 addToBar: isSideBreakpoint && [
43 h(Box, { flex: 1 }),
44 // not really useful, but users misled in thinking it's a dialog will find satisfaction in dismissing the form
45 vfsNodeIcon(selectedFiles[0] as VfsNode),
45 - h(IconBtn, { icon: Close, title: "Close", onClick: selectNone })
46 + h(IconBtn, { icon: Close, title: "Close", onClick: closeForm })
47 ],
48 statusApi,
49 file: selectedFiles[0] as VfsNode // it's actually Snapshot<VfsNode> but it's easier this way
@@ -69,7 +70,7 @@ export default function VfsPage() {
70 title: selectedFiles.length > 1 ? "Multiple selection" :
71 h(Flex, {}, vfsNodeIcon(selectedFiles[0] as VfsNode), selectedFiles[0].name || "Home"),
72 Content: () => sideContent,
72 - onClose: selectNone,
73 + onClose: closeForm,
74 })
75 setCloseDialog(() => close)
76 return close
@@ -124,7 +125,7 @@ export default function VfsPage() {
125 h(Grid, { item: true, [sideBreakpoint]: 7, lg: 6, xl: 5 },
126 h(Typography, { variant: 'h6', mb:1, }, "Virtual File System"),
127 h(VfsMenuBar, { statusApi }),
127 - vfs && h(VfsTree, { id2node, statusApi }) ),
128 + vfs && h(VfsTree, { id2node, statusApi, onSelect: () => setHideForm(false) }) ),
129 isSideBreakpoint && sideContent && h(Grid, { item: true, [sideBreakpoint]: true, maxWidth:'100%' },
130 h(Card, { sx: { overflow: 'initial' } }, // overflow is incompatible with stickyBar
131 h(CardContent, {}, sideContent) ))
admin/src/VfsTree.ts
+3 -2
@@ -8,7 +8,7 @@ import { ChevronRight, ExpandMore, TheaterComedy, Folder, Home, Link, InsertDriv
8 } from '@mui/icons-material'
9 import { Box } from '@mui/material'
10 import { reloadVfs, VfsNode } from './VfsPage'
11 -import { onlyTruthy, Who, with_ } from './misc'
11 +import { Callback, onlyTruthy, Who, with_ } from './misc'
12 import { iconTooltip } from './mui'
13 import { apiCall, ApiObject } from './api'
14 import { alertDialog, confirmDialog } from './dialog'
@@ -17,7 +17,7 @@ import _ from 'lodash'
17 export const FolderIcon = Folder
18 export const FileIcon = InsertDriveFileOutlined
19
20 -export default function VfsTree({ id2node, statusApi }:{ id2node: Map<string, VfsNode>, statusApi: ApiObject }) {
20 +export default function VfsTree({ id2node, statusApi, onSelect }:{ id2node: Map<string, VfsNode>, statusApi: ApiObject, onSelect: Callback }) {
21 const { vfs, selectedFiles } = useSnapState()
22 const [selected, setSelected] = useState<string[]>(selectedFiles.map(x => x.id)) // try to restore selection after reload
23 const [expanded, setExpanded] = useState(Array.from(id2node.keys()))
@@ -42,6 +42,7 @@ export default function VfsTree({ id2node, statusApi }:{ id2node: Map<string, Vf
42 if (typeof ids === 'string') return // shut up ts
43 setSelected(ids)
44 state.selectedFiles = onlyTruthy(ids.map(id => id2node.get(id)))
45 + onSelect()
46 }
47 }, recur(vfs as Readonly<VfsNode>))
48