@samitouri / QOSami-HFS / commits / fa5ab7b0

admin: ctrl+DIGIT on keyboard to switch page

Massimo Melina committed Jan 3, 2024 at 11:50 UTC fa5ab7b078b105a7263d463b9f38f893037f09d4
2 files changed +13 -1
README.md
+1
@@ -186,6 +186,7 @@ Some actions you can take for improved security:
186 - Appending `?login=USER:PASSWORD` will automatically log in the browser
187 - Appending `?overwrite` on uploads, will try override the dont_overwrite_uploading configuration, provided you also have delete permission
188 - Right-click on "check for updates" will let you input a URL of a version to install
189 +- Admin: ctrl+digit will switch page
190
191 ## Contribute
192
admin/src/App.ts
+12 -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 { createElement as h, Fragment, useState } from 'react'
4 -import { HashRouter, Routes, Route, useLocation } from 'react-router-dom'
4 +import { HashRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom'
5 import MainMenu, { getMenuLabel, mainMenu } from './MainMenu'
6 import { AppBar, Box, Drawer, IconButton, ThemeProvider, Toolbar, Typography } from '@mui/material'
7 import { Dialogs } from './dialog'
@@ -13,6 +13,8 @@ import { LocalizationProvider } from '@mui/x-date-pickers'
13 import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
14 import ConfigFilePage from './ConfigFilePage'
15 import { useSnapState } from './state'
16 +import { useEventListener } from 'usehooks-ts'
17 +import { xlate } from './misc'
18
19 function App() {
20 return h(ThemeProvider, { theme: useMyTheme() },
@@ -42,6 +44,15 @@ function Routed() {
44 const [open, setOpen] = useState(false)
45 const large = useBreakpoint('lg')
46 const xs = current?.noPaddingOnMobile ? 0 : 1
47 + const navigate = useNavigate()
48 + useEventListener('keydown', ({ key, ctrlKey }) => {
49 + if (!ctrlKey) return
50 + const idx = Number(xlate(key, { 0: 10 })) // key 0 is after 9 and works as 10
51 + if (!idx) return
52 + const path = mainMenu[idx - 1]?.path
53 + if (path === undefined) return
54 + navigate(path || '/')
55 + })
56 return h(Fragment, {},
57 !large && h(StickyBar, { title, openMenu: () => setOpen(true) }),
58 !large && h(Drawer, { anchor:'left', open, onClose(){ setOpen(false) } },