Allow to select connection profile with arrow keys
This commit is contained in:
@@ -8,28 +8,45 @@ import { connectionManagerActions } from '../../../actions'
|
|||||||
import { ConnectionOptions } from '../../../model/ConnectionOptions'
|
import { ConnectionOptions } from '../../../model/ConnectionOptions'
|
||||||
import { List, ListSubheader } from '@material-ui/core'
|
import { List, ListSubheader } from '@material-ui/core'
|
||||||
import { Theme, withStyles } from '@material-ui/core/styles'
|
import { Theme, withStyles } from '@material-ui/core/styles'
|
||||||
|
import { useGlobalKeyEventHandler } from '../../../effects/useGlobalKeyEventHandler'
|
||||||
|
import { KeyCodes } from '../../../utils/KeyCodes'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
classes: any
|
classes: any
|
||||||
selected?: string
|
selected?: string
|
||||||
connections: { [s: string]: ConnectionOptions }
|
connections: { [s: string]: ConnectionOptions }
|
||||||
actions: any
|
actions: typeof connectionManagerActions
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProfileList(props: Props) {
|
function ProfileList(props: Props) {
|
||||||
const { actions, classes, connections, selected } = props
|
const { actions, classes, connections, selected } = props
|
||||||
|
|
||||||
return (
|
const selectConnection = (dir: 'next' | 'previous') => (event: KeyboardEvent) => {
|
||||||
<List
|
if (!selected) {
|
||||||
style={{ height: '100%' }}
|
return
|
||||||
component="nav"
|
}
|
||||||
subheader={
|
const indexDirection = dir === 'next' ? 1 : -1
|
||||||
|
const connectionArray = Object.values(connections)
|
||||||
|
const selectedIndex = connectionArray.map(connection => connection.id).indexOf(selected)
|
||||||
|
const nextConnection = connectionArray[selectedIndex + indexDirection]
|
||||||
|
if (nextConnection) {
|
||||||
|
actions.selectConnection(nextConnection.id)
|
||||||
|
}
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
|
||||||
|
useGlobalKeyEventHandler(KeyCodes.arrow_down, selectConnection('next'))
|
||||||
|
useGlobalKeyEventHandler(KeyCodes.arrow_up, selectConnection('previous'))
|
||||||
|
|
||||||
|
const createConectionButton = (
|
||||||
<ListSubheader component="div">
|
<ListSubheader component="div">
|
||||||
<AddButton action={actions.createConnection} />
|
<AddButton action={actions.createConnection} />
|
||||||
Connections
|
Connections
|
||||||
</ListSubheader>
|
</ListSubheader>
|
||||||
}
|
)
|
||||||
>
|
|
||||||
|
return (
|
||||||
|
<List style={{ height: '100%' }} component="nav" subheader={createConectionButton}>
|
||||||
<div className={classes.list}>
|
<div className={classes.list}>
|
||||||
{Object.values(connections).map(connection => (
|
{Object.values(connections).map(connection => (
|
||||||
<ConnectionItem connection={connection} key={connection.id} selected={selected === connection.id} />
|
<ConnectionItem connection={connection} key={connection.id} selected={selected === connection.id} />
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
export enum KeyCodes {
|
export enum KeyCodes {
|
||||||
backspace = 8,
|
backspace = 8,
|
||||||
|
tab = 9,
|
||||||
enter = 13,
|
enter = 13,
|
||||||
escape = 27,
|
escape = 27,
|
||||||
|
arrow_left = 37,
|
||||||
|
arrow_up = 38,
|
||||||
|
arrow_right = 39,
|
||||||
|
arrow_down = 40,
|
||||||
delete = 46,
|
delete = 46,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user