fix: admin/fs: it was not possible to select a single file using keyboard
Massimo Melina committed
Feb 7, 2024 at 00:15 UTC
4921860930f813bf264663ddb706be6a2d5af157
2 files changed
+4
-9
admin/src/VfsPage.ts
-4
@@ -32,10 +32,6 @@ export default function VfsPage() {
32
return b && !ret.includes(b) ? [b, ...ret] : ret
33
}, [status])
34
const single = selectedFiles.length < 2 && (selectedFiles[0] as VfsNode || vfs)
35
- useEffect(() => {
36
- if (isSideBreakpoint && !selectedFiles.length && state.vfs)
37
- state.selectedFiles = [state.vfs]
38
- }, [isSideBreakpoint, selectedFiles, state.vfs])
35
36
const sideContent = !vfs ? null : single ? h(FileForm, {
37
addToBar: isSideBreakpoint && h(Box, { flex: 1, textAlign: 'right', mr: 1, color: '#8883' }, vfsNodeIcon(single)),
admin/src/VfsTree.ts
+4
-5
@@ -7,7 +7,7 @@ import { ChevronRight, ExpandMore, TheaterComedy, Folder, Home, Link, InsertDriv
7
RemoveRedEye, Web, Upload, Cloud, Delete, HighlightOff } from '@mui/icons-material'
8
import { Box } from '@mui/material'
9
import { reloadVfs, VfsNode } from './VfsPage'
10
-import { Callback, onlyTruthy, Who, with_ } from './misc'
10
+import { onlyTruthy, Who, with_ } from './misc'
11
import { iconTooltip } from './mui'
12
import { apiCall, ApiObject } from './api'
13
import { alertDialog, confirmDialog } from './dialog'
@@ -16,7 +16,7 @@ import _ from 'lodash'
16
export const FolderIcon = Folder
17
export const FileIcon = InsertDriveFileOutlined
18
19
-export default function VfsTkree({ id2node, statusApi, onSelect }:{ id2node: Map<string, VfsNode>, statusApi: ApiObject, onSelect?: Callback<VfsNode[]> }) {
19
+export default function VfsTree({ id2node, statusApi }:{ id2node: Map<string, VfsNode>, statusApi: ApiObject }) {
20
const { vfs, selectedFiles } = useSnapState()
21
const [expanded, setExpanded] = useState(Array.from(id2node.keys()))
22
const dragging = useRef<string>()
@@ -28,7 +28,7 @@ export default function VfsTkree({ id2node, statusApi, onSelect }:{ id2node: Map
28
// @ts-ignore the type declared on the lib doesn't seem to be compatible with useRef()
29
ref,
30
expanded,
31
- selected: selectedFiles.map(x => x.id),
31
+ selected: selectedFiles.length ? selectedFiles.map(x => x.id) : ['/'],
32
multiSelect: true,
33
id: treeId,
34
sx: {
@@ -38,8 +38,7 @@ export default function VfsTkree({ id2node, statusApi, onSelect }:{ id2node: Map
38
},
39
onNodeSelect(ev, ids) {
40
if (typeof ids === 'string') return // shut up ts
41
- state.selectedFiles = onlyTruthy(ids.map(id => id2node.get(id)))
42
- onSelect?.(state.selectedFiles)
41
+ state.selectedFiles = onlyTruthy(ids.filter(x => (selectedFiles.length || x !== '/') && x).map(id => id2node.get(id)))
42
}
43
}, recur(vfs as Readonly<VfsNode>))
44