Skip to content

Commit

Permalink
Add more keyboard shorcuts and require shift to use them.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesalmeida committed Oct 1, 2024
1 parent a018462 commit 7c273c7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
33 changes: 21 additions & 12 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,30 @@ function App() {
if (event.target.tagName.toLowerCase() === 'input') {
return; // Exit the function if we're typing in an input field
}

switch (event.key.toUpperCase()) {
case 'F':
handleToggleFrunk();
break;
case 'T':
handleToggleTrunk();
break;
default:
break;

if (event.shiftKey) {
switch (event.key.toUpperCase()) {
case 'F':
handleToggleFrunk();
break;
case 'T':
handleToggleTrunk();
break;
case 'M':
event.preventDefault(); // Prevent 'M' from being typed
const navigateToInput = document.getElementById('navigateTo');
if (navigateToInput) {
navigateToInput.focus();
}
break;
default:
break;
}
}
};

window.addEventListener('keydown', handleKeyDown);

return () => {
window.removeEventListener('keydown', handleKeyDown);
};
Expand Down
14 changes: 8 additions & 6 deletions src/components/GearSelect/GearSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ function GearSelect({ activeGear, onGearSelect }) {
if (event.target.tagName.toLowerCase() === 'input') {
return; // Exit the function if we're typing in an input field
}

const gear = event.key.toUpperCase();
if (['P', 'R', 'N', 'D'].includes(gear)) {
onGearSelect(gear);

if (event.shiftKey) {
const gear = event.key.toUpperCase();
if (['P', 'R', 'N', 'D'].includes(gear)) {
onGearSelect(gear);
}
}
};

window.addEventListener('keydown', handleKeyDown);

return () => {
window.removeEventListener('keydown', handleKeyDown);
};
Expand Down
1 change: 1 addition & 0 deletions src/components/MapNavigation/MapNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export function MapNavigation() {
name="NavigateTo"
defaultValue={inputValue}
onChange={handleInputChange}
id="navigateTo"
/>
{inputValue && (
<button className="clearInput" onClick={clearInput}>
Expand Down
11 changes: 10 additions & 1 deletion src/components/MusicPanel/MusicPanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@
border-radius: 12px;
}

.musicBtn:focus {
outline: none;
}

.musicBtn::-moz-focus-inner {
border: 0;
}

.musicIcon {
/* height: 45%; */
height: 20px;
Expand Down Expand Up @@ -187,4 +195,5 @@
.albumTitle {
/* font-size: 14px; */
}
}
}

35 changes: 32 additions & 3 deletions src/components/MusicPanel/MusicPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export function MusicPanel({ volume }) {
setCurrentTime(currentTimeRef.current);
};

const togglePlayPause = () => {
setIsPlaying(!isPlaying);
};
const togglePlayPause = useCallback(() => {
setIsPlaying(prevIsPlaying => !prevIsPlaying);
}, []);

const handlePrevious = () => {
const now = Date.now();
Expand Down Expand Up @@ -105,6 +105,35 @@ export function MusicPanel({ volume }) {
}
}, [handleProgressBarClick]);

useEffect(() => {
const handleKeyDown = (event) => {
if (event.shiftKey) {
switch (event.key) {
case ' ':
event.preventDefault();
togglePlayPause();
break;
case 'ArrowRight':
event.preventDefault();
handleNext();
break;
case 'ArrowLeft':
event.preventDefault();
handlePrevious();
break;
default:
break;
}
}
};

window.addEventListener('keydown', handleKeyDown);

return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [togglePlayPause, handleNext, handlePrevious]);

return (
<div className="musicPanel">
<div className="albumArt">
Expand Down

0 comments on commit 7c273c7

Please sign in to comment.