import { InlineCluster } from "@bedrock-layout/inline-cluster"; import { findIndex } from "lodash"; import { useDispatch, useSelector } from "react-redux"; import { broadcastDirectorSelector } from "../../../../features/broadcast/director/broadcastDirectorSelector"; import { pushSelectedCars, clearSelectedCars, removeSelectedCars } from "../../../../features/broadcast/director/broadcastDirectorSlice"; import { eventSelector } from "../../../../features/event/eventSelector"; import { Car } from "../../../../types/state"; import { carMatch } from "../../../../utils/comparators"; import { DriverLabel, GridItem, SelectionLabel } from "./styles"; export function GridSelection() { const dispatch = useDispatch(); const { grid, } = useSelector(eventSelector); const { selectedCars, } = useSelector(broadcastDirectorSelector); const carClick = (car: Car, selected: boolean) => () => { if (selected) { dispatch(removeSelectedCars(car)); } else { dispatch(pushSelectedCars(car)); } }; const carDoubleClick = (car: Car) => () => { dispatch(clearSelectedCars(car)); }; return ( {grid.map(car => { const selectedIndex = findIndex(selectedCars, carMatch(car)); const selected = selectedIndex !== -1; const onClick = carClick(car, selected); const onDoubleClick = carDoubleClick(car); return ( {car.driver.initials} {selected && ( {selectedIndex + 1} )} ); })} ); }