Skip to content

Commit

Permalink
Add keyboard shortcuts for gear select and toggling frunk and trunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesalmeida committed Sep 29, 2024
1 parent 58e9dae commit 38ab7ec
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 33 deletions.
22 changes: 0 additions & 22 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,6 @@
font-weight: 400;
}

.gearSelect {
display: flex;
gap: 5px;
}

.gearSelectIcon {
color: #4e4e4e;
font-weight: 400;
cursor: pointer;
transition: all 0.3s ease;
}

.gearSelectIcon:hover {
background-color: #f0f0f0;
}

.gearSelectIcon.active {
color: #000000;
font-weight: 800;
transform: scale(0.95);
}

.appShelfContainer {
position: relative;
width: 100%;
Expand Down
35 changes: 24 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CarLock from './components/CarLock/CarLock';
import VolumeControl from './components/VolumeControl/VolumeControl';
import TemperatureControl from './components/TemperatureControl/TemperatureControl';
import BatteryStatus from './components/BatteryStatus/BatteryStatus';
import GearSelect from './components/GearSelect/GearSelect';
import { useDots } from './utils/dots';
import './App.css';

Expand Down Expand Up @@ -257,6 +258,28 @@ function App() {
return () => clearTimeout(fallbackTimer);
}, []);

// Add this new useEffect for keyboard shortcuts
useEffect(() => {
const handleKeyDown = (event) => {
switch (event.key.toUpperCase()) {
case 'F':
handleToggleFrunk();
break;
case 'T':
handleToggleTrunk();
break;
default:
break;
}
};

window.addEventListener('keydown', handleKeyDown);

return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, []); // Empty dependency array means this effect runs once on mount

return (
<CarLockProvider>
<UserProfileProvider>
Expand All @@ -273,17 +296,7 @@ function App() {
onResize={handleLeftPanelResize}
>
<div className="carStatusIcons">
<div className="gearSelect no-select">
{['P', 'R', 'N', 'D'].map((gear) => (
<span
key={gear}
className={`gearSelectIcon ${activeGear === gear ? 'active' : ''}`}
onClick={() => handleGearSelect(gear)}
>
{gear}
</span>
))}
</div>
<GearSelect activeGear={activeGear} onGearSelect={handleGearSelect} />
<BatteryStatus />
</div>
<div className="carModelStatus">
Expand Down
21 changes: 21 additions & 0 deletions src/components/GearSelect/GearSelect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.gearSelect {
display: flex;
gap: 5px;
}

.gearSelectIcon {
color: #4e4e4e;
font-weight: 400;
cursor: pointer;
transition: all 0.3s ease;
}

.gearSelectIcon:hover {
background-color: #f0f0f0;
}

.gearSelectIcon.active {
color: #000000;
font-weight: 800;
transform: scale(0.95);
}
35 changes: 35 additions & 0 deletions src/components/GearSelect/GearSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useEffect } from 'react';
import './GearSelect.css';

function GearSelect({ activeGear, onGearSelect }) {
useEffect(() => {
const handleKeyDown = (event) => {
const gear = event.key.toUpperCase();
if (['P', 'R', 'N', 'D'].includes(gear)) {
onGearSelect(gear);
}
};

window.addEventListener('keydown', handleKeyDown);

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

return (
<div className="gearSelect no-select">
{['P', 'R', 'N', 'D'].map((gear) => (
<span
key={gear}
className={`gearSelectIcon ${activeGear === gear ? 'active' : ''}`}
onClick={() => onGearSelect(gear)}
>
{gear}
</span>
))}
</div>
);
}

export default GearSelect;

0 comments on commit 38ab7ec

Please sign in to comment.