Skip to content

Commit 4ebe72c

Browse files
committed
refactor components structure for standings
1 parent e918114 commit 4ebe72c

20 files changed

+170
-76
lines changed

.storybook/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from './telemetryDecorator';
1+
export * from './telemetryDecorator';
2+
export * from './DynamicTelemetrySelector';

src/frontend/components/Standings/Relative.stories.tsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Meta, StoryObj } from '@storybook/react';
22
import { Relative } from './Relative';
3-
import { TelemetryDecorator } from '@irdashies/storybook';
4-
import { DynamicTelemetrySelector, TEST_DATA_DIRS } from './DynamicTelemetrySelector';
3+
import {
4+
TelemetryDecorator,
5+
DynamicTelemetrySelector,
6+
} from '@irdashies/storybook';
57
import { useState } from 'react';
68

79
export default {
@@ -11,11 +13,6 @@ export default {
1113
exclude: ['telemetryPath'],
1214
},
1315
},
14-
loaders: [
15-
async () => {
16-
return { testDataDirs: TEST_DATA_DIRS };
17-
},
18-
],
1916
} as Meta<typeof Relative>;
2017

2118
type Story = StoryObj<typeof Relative>;
@@ -25,19 +22,23 @@ export const Primary: Story = {
2522
};
2623

2724
export const DynamicTelemetry: Story = {
28-
decorators: [(Story, context) => {
29-
const [selectedPath, setSelectedPath] = useState('/test-data/1747384273173');
30-
31-
return (
32-
<>
33-
<DynamicTelemetrySelector
34-
onPathChange={setSelectedPath}
35-
initialPath={selectedPath}
36-
/>
37-
{TelemetryDecorator(selectedPath)(Story, context)}
38-
</>
39-
);
40-
}],
25+
decorators: [
26+
(Story, context) => {
27+
const [selectedPath, setSelectedPath] = useState(
28+
'/test-data/1747384273173'
29+
);
30+
31+
return (
32+
<>
33+
<DynamicTelemetrySelector
34+
onPathChange={setSelectedPath}
35+
initialPath={selectedPath}
36+
/>
37+
{TelemetryDecorator(selectedPath)(Story, context)}
38+
</>
39+
);
40+
},
41+
],
4142
};
4243

4344
export const MultiClassPCCWithClio: Story = {

src/frontend/components/Standings/Relative.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useAutoAnimate } from '@formkit/auto-animate/react';
2-
import { DriverInfoRow } from './DriverInfoRow/DriverInfoRow';
2+
import { DriverInfoRow } from './components/DriverInfoRow/DriverInfoRow';
33
import { useDriverRelatives } from './hooks/useDriverRelatives';
4-
import { DriverRatingBadge } from './DriverRatingBadge/DriverRatingBadge';
5-
import { SessionBar } from './SessionBar/SessionBar';
6-
import { SessionFooter } from './SessionFooter/SessionFooter';
4+
import { DriverRatingBadge } from './components/DriverRatingBadge/DriverRatingBadge';
5+
import { SessionBar } from './components/SessionBar/SessionBar';
6+
import { SessionFooter } from './components/SessionFooter/SessionFooter';
77

88
export const Relative = () => {
99
const standings = useDriverRelatives({ buffer: 3 });

src/frontend/components/Standings/Standings.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Meta, StoryObj } from '@storybook/react';
22
import { Standings } from './Standings';
3-
import { TelemetryDecorator } from '@irdashies/storybook';
4-
import { DynamicTelemetrySelector } from './DynamicTelemetrySelector';
3+
import { TelemetryDecorator, DynamicTelemetrySelector } from '@irdashies/storybook';
54
import { useState } from 'react';
65

76
export default {

src/frontend/components/Standings/Standings.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { DriverRatingBadge } from './DriverRatingBadge/DriverRatingBadge';
2-
import { DriverInfoRow } from './DriverInfoRow/DriverInfoRow';
1+
import { Fragment } from 'react';
32
import { useAutoAnimate } from '@formkit/auto-animate/react';
4-
import { DriverClassHeader } from './DriverClassHeader/DriverClassHeader';
5-
import { SessionBar } from './SessionBar/SessionBar';
6-
import { Fragment } from 'react/jsx-runtime';
3+
import { DriverClassHeader } from './components/DriverClassHeader/DriverClassHeader';
4+
import { DriverInfoRow } from './components/DriverInfoRow/DriverInfoRow';
5+
import { DriverRatingBadge } from './components/DriverRatingBadge/DriverRatingBadge';
6+
import { RatingChange } from './components/RatingChange/RatingChange';
7+
import { SessionBar } from './components/SessionBar/SessionBar';
8+
import { SessionFooter } from './components/SessionFooter/SessionFooter';
79
import { useCarClassStats, useDriverStandings } from './hooks';
8-
import { SessionFooter } from './SessionFooter/SessionFooter';
910

1011
export const Standings = () => {
1112
const [parent] = useAutoAnimate();
@@ -37,7 +38,7 @@ export const Standings = () => {
3738
hasFastestTime={result.hasFastestTime}
3839
delta={result.delta}
3940
position={result.classPosition}
40-
iratingChange={result.iratingChange}
41+
iratingChange={<RatingChange value={result.iratingChange} />}
4142
lastTime={result.lastTime}
4243
fastestTime={result.fastestTime}
4344
onPitRoad={result.onPitRoad}

src/frontend/components/Standings/DriverInfoRow/DriverInfoRow.stories.tsx renamed to src/frontend/components/Standings/components/DriverInfoRow/DriverInfoRow.stories.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DriverRatingBadge } from '../DriverRatingBadge/DriverRatingBadge';
44
import { useAutoAnimate } from '@formkit/auto-animate/react';
55
import { SessionBar } from '../SessionBar/SessionBar';
66
import { SessionFooter } from '../SessionFooter/SessionFooter';
7+
import { RatingChange } from '../RatingChange/RatingChange';
78

89
export default {
910
component: DriverInfoRow,
@@ -108,23 +109,23 @@ export const IRatingChange: Story = {
108109
name: 'iRating Positive Change',
109110
args: {
110111
...Primary.args,
111-
iratingChange: 10,
112+
iratingChange: <RatingChange value={10} />,
112113
},
113114
};
114115

115116
export const IRatingChangeNegative: Story = {
116117
name: 'iRating Negative Change',
117118
args: {
118119
...Primary.args,
119-
iratingChange: -58,
120+
iratingChange: <RatingChange value={-58} />,
120121
},
121122
};
122123

123124
export const IRatingNoChange: Story = {
124125
name: 'iRating No Change',
125126
args: {
126127
...Primary.args,
127-
iratingChange: 0,
128+
iratingChange: <RatingChange value={0} />,
128129
},
129130
};
130131

src/frontend/components/Standings/DriverInfoRow/DriverInfoRow.tsx renamed to src/frontend/components/Standings/components/DriverInfoRow/DriverInfoRow.tsx

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { useMemo } from 'react';
21
import {
32
SpeakerHighIcon,
4-
CaretUpIcon,
5-
CaretDownIcon,
6-
MinusIcon,
73
} from '@phosphor-icons/react';
84
import { getTailwindStyle } from '@irdashies/utils/colors';
95
import { formatTime } from '@irdashies/utils/time';
@@ -18,7 +14,7 @@ interface DriverRowInfoProps {
1814
delta?: number;
1915
position: number;
2016
badge: React.ReactNode;
21-
iratingChange?: number;
17+
iratingChange?: React.ReactNode;
2218
lastTime?: number;
2319
fastestTime?: number;
2420
onPitRoad?: boolean;
@@ -51,30 +47,6 @@ export const DriverInfoRow = ({
5147
const lastTimeString = formatTime(lastTime);
5248
const fastestTimeString = formatTime(fastestTime);
5349

54-
const iratingChangeDisplay = useMemo(() => {
55-
if (iratingChange === undefined || isNaN(iratingChange)) {
56-
return { text: '-', color: 'text-gray-400' };
57-
}
58-
const roundedChange = Math.round(iratingChange);
59-
let text: string;
60-
let color = 'text-gray-400';
61-
let icon: React.ReactNode;
62-
63-
if (roundedChange > 0) {
64-
text = `${roundedChange}`;
65-
color = 'text-green-400';
66-
icon = <CaretUpIcon size={10} />;
67-
} else if (roundedChange < 0) {
68-
text = `${Math.abs(roundedChange)}`;
69-
color = 'text-red-400';
70-
icon = <CaretDownIcon size={10} />;
71-
} else {
72-
text = `${roundedChange}`;
73-
icon = <MinusIcon size={10} />;
74-
}
75-
return { text, color, icon };
76-
}, [iratingChange]);
77-
7850
return (
7951
<tr
8052
key={carIdx}
@@ -115,11 +87,8 @@ export const DriverInfoRow = ({
11587
</td>
11688
<td>{badge}</td>
11789
{iratingChange !== undefined && (
118-
<td className={`px-2 text-left ${iratingChangeDisplay.color}`}>
119-
<span className="flex items-center gap-0.5">
120-
{iratingChangeDisplay.icon}
121-
{iratingChangeDisplay.text}
122-
</span>
90+
<td className="px-2 text-left">
91+
{iratingChange}
12392
</td>
12493
)}
12594
<td className={`px-2`}>{delta?.toFixed(1)}</td>

0 commit comments

Comments
 (0)