diff --git a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx index ce04dc2..dff4750 100644 --- a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx +++ b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx @@ -14,7 +14,7 @@ import { setChyronsOpenState, } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice"; import { flagModeList, getChyronModesList, getChyronSubModesList } from "../../../../domain/data/broadcastGraphics"; -import { BGChyronDriver, BGChyronMode, BGChyrons, BGChyronSubMode, Car, FlagMode } from "../../../../types/state"; +import { BGChyronDriver, BGChyronMode, BGChyrons, BGChyronSubMode, Car, FlagMode, GridSpot } from "../../../../types/state"; import { SlotSelector } from "../../../Common/Inputs/SlotSelector"; import { Button, CloseButton, OpenButton, Title } from "./styles"; @@ -62,29 +62,31 @@ export function ChyronsDirectorControls() { const buildDriver = () => { if (selectedCars.length === 0) return; - let primaryCar = grid[selectedCars[0]]; - let secondaryCar = selectedCars.length > 1 ? grid[selectedCars[1]] : null; + let primaryCarGridSpot = selectedCars[0]; + let secondaryCarGridSpot = selectedCars[1] ?? -1; - // Auto-sort drivers by position so trailing car always appears second. - if (chyronSubMode === "medium" && secondaryCar != null - && secondaryCar.position < primaryCar.position) { - secondaryCar = grid[selectedCars[0]]; - primaryCar = grid[selectedCars[1]]; + // Auto-sort drivers by position so trailing car appears second on mounting. + if (chyronSubMode === "medium" && secondaryCarGridSpot != -1 + && grid[secondaryCarGridSpot].position < grid[primaryCarGridSpot].position) { + secondaryCarGridSpot = selectedCars[0]; + primaryCarGridSpot = selectedCars[1]; } + const newChyrons: BGChyrons = { openState: 0, mode: chyronMode, subMode: chyronSubMode, driver: { - primary: buildDriverChyron(primaryCar), - secondary: secondaryCar != null ? buildDriverChyron(secondaryCar) : null, + primary: buildDriverChyron(primaryCarGridSpot), + secondary: secondaryCarGridSpot !== -1 + ? buildDriverChyron(secondaryCarGridSpot) : null, }, }; dispatch(setChyrons(newChyrons)); }; - const buildDriverChyron = (car: Car): BGChyronDriver => ({ - car, + const buildDriverChyron = (carGridSpot: GridSpot): BGChyronDriver => ({ + carGridSpot, flagMode, showPosFlag: posFlag, showDriverNumber: driverNum, diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx index 39d12e0..5948917 100644 --- a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx +++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx @@ -1,11 +1,12 @@ import { useSpring } from "@react-spring/web"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { BGChyronDriver, BGChyronSubMode, CarStatus, OpenState } from "../../../../types/state"; import { DebugDurationProps } from "../../../../types/style"; import { clearChyrons } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice"; import { theme } from "../../../../shared/theme"; import { outlineClipPath } from "../../../../utils/styling"; +import { eventSelector } from "../../../../features/event/eventSelector"; import { DriverNumber } from "../../Common/DriverNumber"; import { AngledFlag } from "../../Common/AngledFlag"; @@ -45,7 +46,9 @@ export function ChyronDriver({ : subMode === "large" ? [638, 98] : [0, 0]; - const { car, flagMode, showPosFlag, showDriverNumber, showPortrait } = chyronData; + const { carGridSpot, flagMode, showPosFlag, showDriverNumber, showPortrait } = chyronData; + const { grid } = useSelector(eventSelector); + const car = grid[carGridSpot]; const flagProps = flagMode === "country" ? { flagMode, flag: car.driver.nationality } diff --git a/src/types/state.ts b/src/types/state.ts index e29d44e..fbbf7a2 100644 --- a/src/types/state.ts +++ b/src/types/state.ts @@ -321,7 +321,7 @@ export interface BGChyrons extends BGBaseState { } export interface BGChyronDriver { - car: Car; + carGridSpot: GridSpot; flagMode: FlagMode; showPosFlag: boolean; showDriverNumber: boolean;