admin/home: nicer and warn about empty vfs
Massimo Melina committed
Feb 11, 2022 at 18:02 UTC
34d84aaefd555c46c94bd5dfb0cb6540ac947b64
4 files changed
+24
-22
admin/src/HomePage.ts
+21
-9
@@ -1,19 +1,31 @@
1
import { createElement as h } from 'react'
2
-import { Box, Link, Typography } from '@mui/material'
2
+import { Alert, Box, Link } from '@mui/material'
3
import { useApi } from './api'
4
import { spinner } from './misc'
5
+import { Launch } from '@mui/icons-material'
6
+import { Link as RouterLink } from 'react-router-dom'
7
8
export default function HomePage() {
7
- const [res] = useApi('get_status')
8
- const { http, https } = res || {}
9
+ const [status] = useApi('get_status')
10
+ const [vfs] = useApi('get_vfs')
11
+ const { http, https } = status || {}
12
const secure = !http?.active && https?.active ? 's' : ''
13
const srv = secure ? https : (http?.active && http)
14
const href = srv && `http${secure}://`+window.location.hostname + (srv.port === (secure ? 443 : 80) ? '' : ':'+srv.port)
12
- return h(Box, { flex: 1 },
13
- h(Typography, { variant: 'h4' },
14
- !res ? spinner()
15
- : href ? h(Link, { target:'frontend', href }, "Open frontend interface")
16
- : "Frontend switched off",
15
+ return !status ? spinner() :
16
+ h(Box, { display:'flex', gap: 2, flexDirection:'column' },
17
+ href ? h(Box, {},
18
+ h(Alert, { severity: 'success' }, "Server is working"),
19
+ h(Box, { mt:2, fontSize:'200%' },
20
+ h(Link, { target:'frontend', href }, "Open frontend interface",
21
+ h(Launch, { sx: { ml:1, mt:1 } }),
22
+ )
23
+ ),
24
+ h(Box, { color:'text.secondary' },
25
+ `Inside frontend your users can see the files and folders you decide in the File System.`)
26
+ ) : h(Alert, { severity: 'warning' }, "Frontend switched off"),
27
+
28
+ vfs?.root && !vfs.root.children?.length && !vfs.root.source &&
29
+ h(Alert, { severity: 'warning', sx:{ mt:2 } }, "You have no files shared. Go add some in the ", h(RouterLink, { to:'fs' }, h(Link, {}, `File System page.`)))
30
)
18
- )
31
}
admin/src/MainMenu.ts
+1
-1
@@ -21,7 +21,7 @@ export const mainMenu: MenuEntry[] = [
21
{ path: '', icon: Public, label: 'Home', title: 'Admin interface', comp: HomePage },
22
{ path: 'monitor', icon: Monitor, comp: MonitorPage },
23
{ path: 'configuration', icon: Settings, comp: ConfigPage },
24
- { path: 'vfs', icon: AccountTree, label: 'File System', comp: VfsPage },
24
+ { path: 'fs', icon: AccountTree, label: 'File System', comp: VfsPage },
25
{ path: 'accounts', icon: ManageAccounts, comp: AccountsPage },
26
]
27
admin/src/misc.ts
-12
@@ -20,18 +20,6 @@ export function getCookie(name: string) {
20
return ''
21
}
22
23
-export function usePrevious(value: any) {
24
- const ref = useRef(value)
25
- const ret = ref.current
26
- ref.current = value
27
- return ret
28
-}
29
-
30
-export function getOrSet<T>(o:any, k:string, creator:()=>T): T {
31
- return k in o ? o[k]
32
- : (o[k] = creator())
33
-}
34
-
23
export function formatBytes(n: number, post: string = 'B', k=1024) {
24
if (isNaN(Number(n)) || n < 0)
25
return ''
todo.md
+2
@@ -1,4 +1,6 @@
1
# To do
2
+- admin/home: report HFS version
3
+- admin/home: report busy port(s) with process name
4
- admin: warn in case of items with same name
5
- password protect admin
6
- explain fields in admin