lbry-desktop/ui/effects/use-history-nav.js
infiinte-persistence d0f42ce6b3 Desktop: Enable 'Alt+Left/Right' for history navigation.
## Why
- Consistent behavior across Web and Desktop.
2020-12-30 14:55:24 -05:00

26 lines
682 B
JavaScript

import { useEffect } from 'react';
export default function useHistoryNav(history) {
useEffect(() => {
const handleKeyPress = e => {
if ((e.metaKey || e.altKey) && !e.ctrlKey && !e.shiftKey) {
switch (e.code) {
case 'ArrowLeft':
e.preventDefault();
history.goBack();
break;
case 'ArrowRight':
e.preventDefault();
history.goForward();
break;
default:
// Do nothing
break;
}
}
};
window.addEventListener('keydown', handleKeyPress);
return () => window.removeEventListener('keydown', handleKeyPress);
}, []);
}