Skip to content

Commit 0fe13a0

Browse files
committed
tidy up coalescing settings
1 parent ca22809 commit 0fe13a0

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

src/frontend/components/Input/InputBar/InputBar.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@ const INPUT_CONFIG = [
88
{ key: 'throttle', color: getColor('green') }
99
] as const;
1010

11-
export interface InputTraceProps {
11+
export interface InputBarProps {
1212
brake?: number;
1313
throttle?: number;
1414
clutch?: number;
15-
settings: {
15+
settings?: {
1616
includeClutch: boolean;
1717
includeBrake: boolean;
1818
includeThrottle: boolean;
1919
};
2020
}
2121

22-
export const InputBar = ({ brake, throttle, clutch, settings }: InputTraceProps) => {
22+
export const InputBar = ({
23+
brake,
24+
throttle,
25+
clutch,
26+
settings = {
27+
includeClutch: true,
28+
includeBrake: true,
29+
includeThrottle: true,
30+
},
31+
}: InputBarProps) => {
2332
const svgRef = useRef<SVGSVGElement>(null);
2433

2534
useEffect(() => {

src/frontend/components/Input/InputContainer/InputContainer.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,26 @@ export const InputContainer = ({
2727
}: InputProps) => {
2828
return (
2929
<div className="w-full h-full inline-flex gap-1 p-2 flex-row bg-slate-800/50">
30-
{settings?.trace.enabled && <InputTrace input={{ brake, throttle }} settings={settings.trace} />}
31-
{settings?.bar.enabled && <InputBar brake={brake} throttle={throttle} clutch={clutch} settings={settings.bar} />}
32-
{settings?.gear.enabled && <InputGear gear={gear} speedMs={speed} unit={unit} settings={settings.gear} />}
33-
{settings?.steer?.enabled && <InputSteer angleRad={steer} />}
30+
{(settings?.trace?.enabled ?? true) && (
31+
<InputTrace input={{ brake, throttle }} settings={settings?.trace} />
32+
)}
33+
{(settings?.bar?.enabled ?? true) && (
34+
<InputBar
35+
brake={brake}
36+
throttle={throttle}
37+
clutch={clutch}
38+
settings={settings?.bar}
39+
/>
40+
)}
41+
{(settings?.gear?.enabled ?? true) && (
42+
<InputGear
43+
gear={gear}
44+
speedMs={speed}
45+
unit={unit}
46+
settings={settings?.gear}
47+
/>
48+
)}
49+
{(settings?.steer?.enabled ?? true) && <InputSteer angleRad={steer} />}
3450
</div>
3551
);
3652
};

src/frontend/components/Input/InputGear/InputGear.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ export interface InputGearProps {
22
gear?: number;
33
speedMs?: number;
44
unit?: number;
5-
settings: {
5+
settings?: {
66
unit: 'mph' | 'km/h' | 'auto';
77
};
88
}
99

10-
export const InputGear = ({ gear, speedMs, unit, settings }: InputGearProps) => {
11-
const isMetric = (unit === 1 && settings.unit === 'auto') || settings.unit === 'km/h';
10+
export const InputGear = ({
11+
gear,
12+
speedMs,
13+
unit,
14+
settings = { unit: 'auto' },
15+
}: InputGearProps) => {
16+
const isMetric =
17+
(unit === 1 && settings.unit === 'auto') || settings.unit === 'km/h';
1218
const speed = (speedMs ?? 0) * (isMetric ? 3.6 : 2.23694);
1319
const displayUnit = isMetric ? 'km/h' : 'mph';
1420
let gearText = '';

src/frontend/components/Input/InputTrace/InputTrace.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import * as d3 from 'd3';
22
import { useEffect, useRef, useState } from 'react';
3-
import tailwindColors from 'tailwindcss/colors';
3+
import { getColor } from '@irdashies/utils/colors';
44

5-
const BRAKE_COLOR = tailwindColors.red['500'];
6-
const THROTTLE_COLOR = tailwindColors.green['500'];
5+
const BRAKE_COLOR = getColor('red');
6+
const THROTTLE_COLOR = getColor('green');
77

88
export interface InputTraceProps {
99
input: {
1010
brake?: number;
1111
throttle?: number;
1212
};
13-
settings: {
13+
settings?: {
1414
includeThrottle?: boolean;
1515
includeBrake?: boolean;
1616
};
1717
}
1818

19-
export const InputTrace = ({ input, settings }: InputTraceProps) => {
19+
export const InputTrace = ({
20+
input,
21+
settings = { includeThrottle: true, includeBrake: true },
22+
}: InputTraceProps) => {
2023
const { includeThrottle, includeBrake } = settings;
2124
const svgRef = useRef<SVGSVGElement>(null);
2225
const { width, height } = { width: 400, height: 100 };

0 commit comments

Comments
 (0)