Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend/settings): add customisable hotkeys #548

Merged
merged 22 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3dc716d
fix(frontend): remove unused history hotkeys
Harjot1Singh May 7, 2020
607d697
feat(frontend/settings): update hotkeys with required property
Harjot1Singh May 8, 2020
a45816b
feat(frontend/settings): render add button and required + removable h…
Harjot1Singh May 8, 2020
dbc4c69
feat(frontend/settings): remove grid from hotkeys
Harjot1Singh May 23, 2020
b79ab74
feat(frontend/presenter): add copy all lines shortcut functionality
Harjot1Singh May 23, 2020
9325ccd
feat(frontend/settings): add new hotkey and delete hotkey dialogs
Harjot1Singh May 23, 2020
d1835d3
fix(controller/settings): reserve core hotkeys
Harjot1Singh Jul 11, 2020
4eb156e
fix(frontend/presenter): check controller is open before hiding displ…
Harjot1Singh Jul 12, 2020
fec60fd
fix(frontend/presenter): only go to navigator via hotkey if there are…
Harjot1Singh Jul 13, 2020
faca6f1
fix(frontend/settings): remove duplicate hotkey declaration
Harjot1Singh Jul 13, 2020
a68b0b6
feat(frontend/settings): add restricted hotkey list
Harjot1Singh Jul 13, 2020
4a7c979
fix(frontend/settings): fix saving and removal of hotkeys on Mac
Harjot1Singh Jul 13, 2020
e652251
fix(frontend/settings): add enter and return as reserved hotkeys
Harjot1Singh Jul 14, 2020
47a1711
fix(frontend/presenter): fix hotkey sequences bug in React Hotkeys
Harjot1Singh Oct 19, 2020
1b08526
feat(frontend/settings): add zoom option and hotkeys
Harjot1Singh Oct 20, 2020
275b6b2
fix(frontend/settings): add ctrl-r to restricted hotkeys and move to …
Harjot1Singh Oct 20, 2020
648a978
feat(frontend/settings): prevent assigning a hotkey sequence if conflict
Harjot1Singh Oct 20, 2020
a1df048
fix(frontend/settings): remove ctrl+q from restricted hotkeys
Harjot1Singh Oct 23, 2020
a6ee0d0
fix(frontend/settings): improve text in add hotkey dialog
Harjot1Singh Oct 23, 2020
0e104dc
fix(frontend/settings): make colour of disabled save hotkey button re…
Harjot1Singh Oct 23, 2020
a2b2431
fix(frontend/presenter): constrain zoom hotkeys to option range
Harjot1Singh Oct 23, 2020
a309a3c
Merge branch 'dev' into 176-customisable-hotkeys
Harjot1Singh Oct 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions app/frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { PureComponent, lazy, Suspense } from 'react'
import { Route, Switch, BrowserRouter as Router } from 'react-router-dom'
import { configure } from 'react-hotkeys'
import { hot } from 'react-hot-loader/root'
import classNames from 'classnames'

Expand Down Expand Up @@ -39,32 +38,22 @@ class App extends PureComponent {
[ Presenter, PRESENTER_URL ],
]

constructor( props ) {
super( props )

// Configure react-hotkeys
configure( {
ignoreTags: [],
ignoreKeymapAndHandlerChangesByDefault: false,
} )

this.state = {
connected: false,
connectedAt: null,
status: null,
banis: [],
bani: null,
lineId: null,
mainLineId: null,
nextLineId: null,
viewedLines: {},
transitionHistory: {},
latestLines: {},
shabad: null,
recommendedSources: {},
writers: {},
settings: loadSettings(),
}
state = {
connected: false,
connectedAt: null,
status: null,
banis: [],
bani: null,
lineId: null,
mainLineId: null,
nextLineId: null,
viewedLines: {},
transitionHistory: {},
latestLines: {},
shabad: null,
recommendedSources: {},
writers: {},
settings: loadSettings(),
}

componentDidMount() {
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/Controller/Navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Redirect, useLocation } from 'react-router-dom'
import { string, func, bool } from 'prop-types'
import classNames from 'classnames'
import { invert } from 'lodash'
import { GlobalHotKeys } from 'react-hotkeys'
import { stripVishraams } from 'gurmukhi-utils'

import List from '@material-ui/core/List'
Expand All @@ -28,6 +27,7 @@ import { LINE_HOTKEYS } from '../lib/keyMap'
import { ContentContext, HistoryContext } from '../lib/contexts'
import { useCurrentLines } from '../lib/hooks'

import GlobalHotKeys from '../shared/GlobalHotKeys'
import { withNavigationHotkeys } from '../shared/NavigationHotkeys'
import NavigatorHotKeys from '../shared/NavigatorHotkeys'

Expand Down
35 changes: 26 additions & 9 deletions app/frontend/src/Presenter/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { lazy, Suspense, useState, useContext, useRef } from 'react'
import { useMount } from 'react-use'
import { hot } from 'react-hot-loader/root'
import { GlobalHotKeys } from 'react-hotkeys'
import { Route, useHistory, useLocation } from 'react-router-dom'
import IdleTimer from 'react-idle-timer'
import queryString from 'qs'
Expand All @@ -14,7 +13,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPlus } from '@fortawesome/free-solid-svg-icons'

import controller from '../lib/controller'
import { getUrlState, mapPlatformKeys } from '../lib/utils'
import { getUrlState } from '../lib/utils'
import { toggleFullscreen } from '../lib/electron-utils'
import {
CONTROLLER_URL,
Expand All @@ -30,9 +29,12 @@ import {
} from '../lib/consts'
import { GLOBAL_SHORTCUTS } from '../lib/keyMap'
import { SettingsContext } from '../lib/contexts'
import { useCurrentLines } from '../lib/hooks'
import { OPTIONS } from '../lib/options'

import ThemeLoader from '../shared/ThemeLoader'
import Loader from '../shared/Loader'
import GlobalHotKeys from '../shared/GlobalHotKeys'
import NavigatorHotKeys from '../shared/NavigatorHotkeys'
import { withErrorFallback } from '../shared/ErrorFallback'
import CopyHotkeys from '../shared/CopyHotkeys'
Expand Down Expand Up @@ -67,8 +69,17 @@ const Presenter = () => {
const onIdle = () => setIdle( true )
const onActive = () => setIdle( false )

const lines = useCurrentLines()

const isControllerOpen = pathname.includes( CONTROLLER_URL )

const { local: localSettings } = useContext( SettingsContext )
const {
theme: { themeName },
layout: { controllerZoom: zoom },
hotkeys,
} = localSettings

/**
* Sets the query string parameters, retaining any currently present.
* @param params The query string parameters.
Expand Down Expand Up @@ -100,6 +111,12 @@ const Presenter = () => {
search: queryString.stringify( { [ STATES.controllerOnly ]: true } ),
} )

const { controllerZoom } = OPTIONS
const setZoom = controllerZoom => controller.setSettings( { layout: { controllerZoom } } )
const zoomInController = () => setZoom( Math.min( controllerZoom.max, zoom + 0.1 ) )
const zoomOutController = () => setZoom( Math.max( controllerZoom.min, zoom - 0.1 ) )
const zoomResetController = () => setZoom( 1 )

/**
* Toggles the given query string parameter.
* @param query The query string parameter to toggle.
Expand Down Expand Up @@ -135,13 +152,16 @@ const Presenter = () => {

// Global Hotkey Handlers
const hotkeyHandlers = preventDefault( {
[ GLOBAL_SHORTCUTS.zoomInController.name ]: zoomInController,
[ GLOBAL_SHORTCUTS.zoomOutController.name ]: zoomOutController,
[ GLOBAL_SHORTCUTS.zoomResetController.name ]: zoomResetController,
[ GLOBAL_SHORTCUTS.toggleController.name ]: toggleController,
[ GLOBAL_SHORTCUTS.newController.name ]: () => controller.openWindow( `${CONTROLLER_URL}?${STATES.controllerOnly}=true`, { alwaysOnTop: true } ),
[ GLOBAL_SHORTCUTS.settings.name ]: () => controller.openWindow( SETTINGS_URL ),
[ GLOBAL_SHORTCUTS.search.name ]: () => go( SEARCH_URL ),
[ GLOBAL_SHORTCUTS.history.name ]: () => go( HISTORY_URL ),
[ GLOBAL_SHORTCUTS.bookmarks.name ]: () => go( BOOKMARKS_URL ),
[ GLOBAL_SHORTCUTS.navigator.name ]: () => go( NAVIGATOR_URL ),
[ GLOBAL_SHORTCUTS.navigator.name ]: () => lines.length && go( NAVIGATOR_URL ),
[ GLOBAL_SHORTCUTS.clearDisplay.name ]: controller.clear,
[ GLOBAL_SHORTCUTS.toggleFullscreenController.name ]: toggleFullscreenController,
[ GLOBAL_SHORTCUTS.toggleFullscreen.name ]: toggleFullscreen,
Expand All @@ -152,9 +172,6 @@ const Presenter = () => {
if ( isMobile ) setFullscreenController()
} )

const { local: localSettings } = useContext( SettingsContext )
const { theme: { themeName }, hotkeys } = localSettings

// Required for mouse shortcuts
const presenterRef = useRef( null )

Expand All @@ -172,15 +189,15 @@ const Presenter = () => {
/>
)}

<GlobalHotKeys keyMap={mapPlatformKeys( hotkeys )} handlers={hotkeyHandlers}>
<GlobalHotKeys keyMap={hotkeys} handlers={hotkeyHandlers}>
<NavigatorHotKeys active={!isControllerOpen} mouseTargetRef={presenterRef}>
<CopyHotkeys>

<Suspense fallback={<Loader />}>
{!controllerOnly && <Display settings={localSettings} />}
{!( isControllerOpen && controllerOnly ) && <Display settings={localSettings} />}
</Suspense>

<div className={classNames( 'controller-container', { fullscreen: controllerOnly } )}>
<div className={classNames( 'controller-container', { fullscreen: controllerOnly } )} style={{ zoom }}>
<IconButton className="expand-icon" onClick={toggleController}>
<FontAwesomeIcon icon={faPlus} />
</IconButton>
Expand Down
82 changes: 0 additions & 82 deletions app/frontend/src/Settings/Hotkeys.js

This file was deleted.

Loading