diff --git a/src/common/store/auth/actions.ts b/src/common/store/auth/actions.ts index 4b3781cf..bac884dd 100755 --- a/src/common/store/auth/actions.ts +++ b/src/common/store/auth/actions.ts @@ -12,11 +12,12 @@ import { ObjectTypes, PlaylistTypes } from '../objects'; import { getPlaylist, setObject } from '../objects/actions'; import { getPlaylistObjectSelector } from '../objects/selectors'; import { AuthActionTypes } from './types'; +import { AppActionTypes } from '../app'; export function logout(): ThunkResult { return dispatch => { dispatch({ - type: 'APP_RESET_STORE' + type: AppActionTypes.RESET_STORE }); dispatch(replace('/login')); dispatch(setToken(null)); diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 6f15fcb9..da9de8a1 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -1,6 +1,6 @@ import { EVENTS } from '@common/constants/events'; import { StoreState } from '@common/store'; -import { stopWatchers } from '@common/store/actions'; +import { stopWatchers, toggleStatus } from '@common/store/actions'; import { ConnectedRouter } from 'connected-react-router'; // eslint-disable-next-line import/no-extraneous-dependencies import { ipcRenderer } from 'electron'; @@ -27,9 +27,32 @@ export const App: FC = ({ history, store }) => { ipcRenderer.send(EVENTS.APP.NAVIGATE); }); + const onKeyUp = (e: KeyboardEvent) => { + // When space bar pressed + if (e.keyCode === 32) { + // Prevent from scrolling + store.dispatch(toggleStatus() as any); + } + }; + + const onKeyDown = (e: KeyboardEvent) => { + // Prevent body from scrolling + if (e.keyCode === 32 && e.target === document.body) { + e.preventDefault(); + return false; + } + + return true; + }; + + window.addEventListener('keydown', onKeyDown); + window.addEventListener('keyup', onKeyUp); + return () => { store.dispatch(stopWatchers() as any); unregister(); + window.removeEventListener('keyup', onKeyUp); + window.removeEventListener('keydown', onKeyDown); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/renderer/app/components/Header/Search/SearchBox.tsx b/src/renderer/app/components/Header/Search/SearchBox.tsx index ade40d22..d902fa21 100644 --- a/src/renderer/app/components/Header/Search/SearchBox.tsx +++ b/src/renderer/app/components/Header/Search/SearchBox.tsx @@ -106,6 +106,7 @@ class SearchBox extends React.Component { placeholder="Search people, tracks and albums" value={query} onKeyPress={this.onKeyPress} + onKeyUp={e => e.stopPropagation()} onChange={this.onChange} /> diff --git a/src/renderer/pages/settings/components/InputConfig.tsx b/src/renderer/pages/settings/components/InputConfig.tsx index c2dd33d4..0442ebc1 100644 --- a/src/renderer/pages/settings/components/InputConfig.tsx +++ b/src/renderer/pages/settings/components/InputConfig.tsx @@ -74,6 +74,7 @@ export class InputConfig extends React.PureComponent { name={name} onChange={(event: React.ChangeEvent) => this.saveDebounced(event.target.value)} placeholder={placeholderText} + onKeyUp={e => e.stopPropagation()} defaultValue={defaultValue} />