diff --git a/src/components/Common/MenuItem.styled.ts b/src/components/Common/MenuItem.styled.ts index cc7bad7..2ed6020 100644 --- a/src/components/Common/MenuItem.styled.ts +++ b/src/components/Common/MenuItem.styled.ts @@ -12,7 +12,7 @@ type MenuItemProps = { }; export const MenuItem = styled(PadBox).attrs(() => ({ padding: ["sm", "lg"], -})) ` +}))` border-radius: ${p => p.theme.design.button.borderRadius}; color: ${p => p.theme.colors.darkGrey}; font-family: ${p => p.theme.fonts.f1Regular}; diff --git a/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx b/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx index 88d8f05..23d1d35 100644 --- a/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx +++ b/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx @@ -1,17 +1,34 @@ +import { useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; + +import { workspaceSelector } from "../../../features/workspace/workspaceSelector"; + import { AngledFlag } from "../../BroadcastGraphics/Common/AngledFlag"; import { BasicBlock } from "./styles"; + export function AngledFlagWorkSpace() { + const { prototypeState } = useSelector(workspaceSelector); + // const dispatch = useDispatch(); + // useEffect(() => { + // dispatch(setPrototypeState({ + // angledFlag: { + // flagA: "GBR", + // flagB: "GBR", + // }, + // })); + // }, [currentWorkspaceId]); + return ( diff --git a/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/AngledFlagPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/AngledFlagPrototypeControls.tsx new file mode 100644 index 0000000..2c4ad61 --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/AngledFlagPrototypeControls.tsx @@ -0,0 +1,32 @@ +import { PadBox } from "@bedrock-layout/padbox"; +import { Split } from "@bedrock-layout/split"; +import { useDispatch, useSelector } from "react-redux"; +import { workspaceSelector } from "../../../../features/workspace/workspaceSelector"; + +import { setPrototypeState } from "../../../../features/workspace/workspaceSlice"; + +import { SlotSelector } from "../../../Common/Inputs/SlotSelector"; + +const countries = [ + "GBR", "NLD", "FIN", "JPN", "FRA", "DEU", "MEX", "POL", "MCO", "CHN", "THA", + "CAN", "RUS", "RAF", "AUS", "ESP", "ITA", +]; +export function AngledFlagPrototypeControls() { + const dispatch = useDispatch(); + const { prototypeState } = useSelector(workspaceSelector); + + const onChange = (flag: "flagA" | "flagB") => (value: string) => { + dispatch(setPrototypeState({ + angledFlag: { + flagA: flag === "flagA" ? value : prototypeState?.angledFlag?.flagA ?? "GBR", + flagB: flag === "flagB" ? value : prototypeState?.angledFlag?.flagB ?? "GBR", + }, + })); + }; + return ( + + + + + ); +} diff --git a/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/index.ts b/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/index.ts new file mode 100644 index 0000000..87fc05a --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/index.ts @@ -0,0 +1 @@ +export * from "./AngledFlagPrototypeControls"; diff --git a/src/components/Workspaces/PrototypingControls/ChyronPrototype/ChyronPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/ChyronPrototype/ChyronPrototypeControls.tsx new file mode 100644 index 0000000..d37a04b --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/ChyronPrototype/ChyronPrototypeControls.tsx @@ -0,0 +1,15 @@ +import { Grid } from "@bedrock-layout/grid"; +import { PadBox } from "@bedrock-layout/padbox"; + +import { GridSelection } from "../GridSelection"; + +export function ChyronPrototypeControls() { + return ( + + + + + Launcher/Closer + + ); +} diff --git a/src/components/Workspaces/PrototypingControls/ChyronPrototype/index.ts b/src/components/Workspaces/PrototypingControls/ChyronPrototype/index.ts new file mode 100644 index 0000000..e5e3b7d --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/ChyronPrototype/index.ts @@ -0,0 +1 @@ +export * from "./ChyronPrototypeControls"; diff --git a/src/components/Workspaces/PrototypingControls/GridSelection/GridSelection.tsx b/src/components/Workspaces/PrototypingControls/GridSelection/GridSelection.tsx new file mode 100644 index 0000000..9f6b7a7 --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/GridSelection/GridSelection.tsx @@ -0,0 +1,58 @@ +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 { selectedCarsAdd, selectedCarsClear, selectedCarsRemove } 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(selectedCarsRemove(car)); + } else { + dispatch(selectedCarsAdd(car)); + } + }; + const carDoubleClick = (car: Car) => () => { + dispatch(selectedCarsClear(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} + )} + + ); + })} + + ); +} diff --git a/src/components/Workspaces/PrototypingControls/GridSelection/index.ts b/src/components/Workspaces/PrototypingControls/GridSelection/index.ts new file mode 100644 index 0000000..86a2232 --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/GridSelection/index.ts @@ -0,0 +1 @@ +export * from "./GridSelection"; diff --git a/src/components/Workspaces/PrototypingControls/GridSelection/styles.ts b/src/components/Workspaces/PrototypingControls/GridSelection/styles.ts new file mode 100644 index 0000000..88f8bb6 --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/GridSelection/styles.ts @@ -0,0 +1,42 @@ +import { PadBox } from "@bedrock-layout/padbox"; +import styled from "styled-components"; + +type GridItemProps = { + selected: boolean, +}; +export const GridItem = styled(PadBox).attrs(() => ({ + padding: ["md", "xs"], +}))` + position: relative; + width: 4.5ch; + border-radius: 0.2em; + + font-family: ${p => p.theme.fonts.f1Regular}; + font-size: 0.8em; + text-align: center; + user-select: none; + + background-color: ${({ selected }) => selected + ? p => p.theme.colors.grey + : p => p.theme.colors.faintGrey}; + + &:hover { + background-color: ${({ selected }) => selected ? p => p.theme.colors.darkGrey : p => p.theme.colors.grey}; + > span { + color: ${p => p.theme.colors.faintGrey}; + } + } + + cursor: pointer; +`; + +export const DriverLabel = styled.span` + text-transform: uppercase; +`; + +export const SelectionLabel = styled.span` + position: absolute; + bottom: 0; + right: 5%; + font-size: 0.3em; +`; diff --git a/src/domain/data/workspaces.ts b/src/domain/data/workspaces.ts index 85f6c06..e235d9b 100644 --- a/src/domain/data/workspaces.ts +++ b/src/domain/data/workspaces.ts @@ -3,7 +3,9 @@ import { WorkspaceId, WorkspaceProperties } from "../../types/state"; // Broadcast Graphics import { ChyronDriver } from "../../components/BroadcastGraphics/Chyrons/Driver"; +import { ChyronPrototypeControls } from "../../components/Workspaces/PrototypingControls/ChyronPrototype"; import { AngledFlagWorkSpace } from "../../components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace"; +import { AngledFlagPrototypeControls } from "../../components/Workspaces/PrototypingControls/AngledFlagPrototype"; type WorkspaceObject = { [id: WorkspaceId]: WorkspaceProperties, @@ -42,12 +44,23 @@ export const workspaces: WorkspaceObject = { height: 500, }, }, + foo: { + name: "Foo", + overlayIds: [], + previewWindowDimensions: { width: 500, height: 500 }, + }, }; -export function fetchBroadcastGraphic(workspaceId: WorkspaceId): [ReactNode, ReactNode] { +export function fetchBroadcastGraphic(workspaceId?: WorkspaceId): [ReactNode, ReactNode] { switch(workspaceId) { - case "chyronDriver": return [ChyronDriver(), null]; - case "angledFlag": return [AngledFlagWorkSpace(), null]; + case "chyronDriver": return [ + ChyronDriver(), + ChyronPrototypeControls(), + ]; + case "angledFlag": return [ + AngledFlagWorkSpace(), + AngledFlagPrototypeControls(), + ]; default: return [null, null]; } } diff --git a/src/features/broadcast/director/broadcastDirectorSlice.ts b/src/features/broadcast/director/broadcastDirectorSlice.ts index ccdf055..0406510 100644 --- a/src/features/broadcast/director/broadcastDirectorSlice.ts +++ b/src/features/broadcast/director/broadcastDirectorSlice.ts @@ -2,14 +2,13 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { findIndex } from "lodash"; import { RootState, Car } from "../../../types/state"; +import { Optional } from "../../../types/util"; +import { carMatch } from "../../../utils/comparators"; const initialState: RootState["broadcastDirector"] = { selectedCars: [], }; -const carMatch = (targetCar: Car) => (checkedCar: Car) => - checkedCar.driver.id === targetCar.driver.id; - export const broadcastDirectorSlice = createSlice({ name: "broadcastDirector", initialState, @@ -31,8 +30,16 @@ export const broadcastDirectorSlice = createSlice({ state.selectedCars.slice(index + 1), ); }, - selectedCarsClear: (state) => { - state.selectedCars = []; + /** + * Shortcut to clear out selected cars. There is also a trick - if you + * @param action Car (optional) - if provided, it'll clear all and add this. + */ + selectedCarsClear: (state, action: PayloadAction>) => { + if (action.payload == null) { + state.selectedCars = []; + } else { + state.selectedCars = [action.payload]; + } }, }, }); diff --git a/src/features/event/eventSlice.ts b/src/features/event/eventSlice.ts index 5313d6b..83114f0 100644 --- a/src/features/event/eventSlice.ts +++ b/src/features/event/eventSlice.ts @@ -1,7 +1,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { CourseFlag, RootState } from "../../types/state"; -import { getDriver } from "../../utils/dataLookup"; +import { cloneDriver } from "../../utils/dataLookup"; const initialState: RootState["event"] = { trackName: "Melbourne", @@ -19,26 +19,26 @@ const initialState: RootState["event"] = { lapCount: 10, }, grid: [ - { position: 1, driver: getDriver("verstappen") }, - { position: 3, driver: getDriver("hamilton") }, - { position: 2, driver: getDriver("bottas") }, - { position: 4, driver: getDriver("perez") }, - { position: 5, driver: getDriver("sainz") }, - { position: 6, driver: getDriver("norris") }, - { position: 7, driver: getDriver("leclerc") }, - { position: 8, driver: getDriver("ricciardo") }, - { position: 9, driver: getDriver("gasly") }, - { position: 10, driver: getDriver("alonso") }, - { position: 11, driver: getDriver("ocon") }, - { position: 12, driver: getDriver("vettel") }, - { position: 13, driver: getDriver("stroll") }, - { position: 14, driver: getDriver("tsunoda") }, - { position: 15, driver: getDriver("russell") }, - { position: 16, driver: getDriver("raikkonen") }, - { position: 17, driver: getDriver("latifi") }, - { position: 18, driver: getDriver("giovinazzi") }, - { position: 19, driver: getDriver("schumacher") }, - { position: 20, driver: getDriver("mazepin") }, + { position: 1, driver: cloneDriver("verstappen") }, + { position: 3, driver: cloneDriver("hamilton") }, + { position: 2, driver: cloneDriver("bottas") }, + { position: 4, driver: cloneDriver("perez") }, + { position: 5, driver: cloneDriver("sainz") }, + { position: 6, driver: cloneDriver("norris") }, + { position: 7, driver: cloneDriver("leclerc") }, + { position: 8, driver: cloneDriver("ricciardo") }, + { position: 9, driver: cloneDriver("gasly") }, + { position: 10, driver: cloneDriver("alonso") }, + { position: 11, driver: cloneDriver("ocon") }, + { position: 12, driver: cloneDriver("vettel") }, + { position: 13, driver: cloneDriver("stroll") }, + { position: 14, driver: cloneDriver("tsunoda") }, + { position: 15, driver: cloneDriver("russell") }, + { position: 16, driver: cloneDriver("raikkonen") }, + { position: 17, driver: cloneDriver("latifi") }, + { position: 18, driver: cloneDriver("giovinazzi") }, + { position: 19, driver: cloneDriver("schumacher") }, + { position: 20, driver: cloneDriver("mazepin") }, ], }; diff --git a/src/features/workspace/workspaceSlice.ts b/src/features/workspace/workspaceSlice.ts index 9913f80..417a956 100644 --- a/src/features/workspace/workspaceSlice.ts +++ b/src/features/workspace/workspaceSlice.ts @@ -1,5 +1,5 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { RootState, WorkspaceId, WorkspaceProperties } from "../../types/state"; +import { PrototypeState, RootState, WorkspaceId, WorkspaceProperties } from "../../types/state"; const initialState: RootState["workspace"] = { workspaceId: "", @@ -9,6 +9,7 @@ const initialState: RootState["workspace"] = { overlayIds: [], previewWindowDimensions: { width: 0, height: 0 }, }, + prototypeState: null, }; export type UpdateWorkspaceAction = { @@ -30,6 +31,9 @@ export const workspaceSlice = createSlice({ state.workspaceId = action.payload.workspaceId; state.workspaceProperties = action.payload.workspaceProperties; }, + setPrototypeState: (state, action: PayloadAction) => { + state.prototypeState = action.payload; + }, }, }); @@ -37,5 +41,6 @@ export const { setWorkspaceId, setAnimatedBG, updateWorkspace, + setPrototypeState, } = workspaceSlice.actions; export default workspaceSlice.reducer; diff --git a/src/store.ts b/src/store.ts index 6ff2325..82c1c83 100644 --- a/src/store.ts +++ b/src/store.ts @@ -3,6 +3,8 @@ import { configureStore, combineReducers } from "@reduxjs/toolkit"; import pageDimensions from "./features/pageDimensions/pageDimensionsSlice"; import workspace from "./features/workspace/workspaceSlice"; import overlayTool from "./features/overlayTool/overlayToolSlice"; +import event from "./features/event/eventSlice"; +import broadcastDirector from "./features/broadcast/director/broadcastDirectorSlice"; import broadcastGraphics from "./features/broadcast/graphics/broadcastGraphicsSlice"; export const store = configureStore({ @@ -10,6 +12,8 @@ export const store = configureStore({ pageDimensions, workspace, overlayTool, + event, + broadcastDirector, broadcastGraphics, }), }); diff --git a/src/types/state.d.ts b/src/types/state.d.ts index 89713e6..9850297 100644 --- a/src/types/state.d.ts +++ b/src/types/state.d.ts @@ -22,6 +22,7 @@ export interface Workspace { workspaceId: WorkspaceId; animatedBG: boolean; workspaceProperties: WorkspaceProperties; + prototypeState: Optional; } export type WorkspaceId = string; @@ -30,6 +31,12 @@ export interface WorkspaceProperties { overlayIds: OverlayIds; previewWindowDimensions: Dimensions; } +export interface PrototypeState { + angledFlag?: { + flagA: string; + flagB: string; + }; +} // Overlay Tool export interface OverlayTool { diff --git a/src/utils/comparators.ts b/src/utils/comparators.ts new file mode 100644 index 0000000..29d5265 --- /dev/null +++ b/src/utils/comparators.ts @@ -0,0 +1,4 @@ +import { Car } from "../types/state"; + +export const carMatch = (targetCar: Car) => (checkedCar: Car) => + checkedCar.driver.id === targetCar.driver.id; diff --git a/src/utils/dataLookup.ts b/src/utils/dataLookup.ts index 6731b3c..dc48757 100644 --- a/src/utils/dataLookup.ts +++ b/src/utils/dataLookup.ts @@ -1,3 +1,4 @@ +import { cloneDeep } from "lodash"; import { drivers, teams, teamNumberStyles, NumberStyle } from "../domain/data/teams"; import { Driver, DriverId, Team, TeamId } from "../types/state"; @@ -11,10 +12,16 @@ import { Driver, DriverId, Team, TeamId } from "../types/state"; export function getDriver(driverId: DriverId): Driver { return drivers[driverId]; } +export function cloneDriver(driverId: DriverId): Driver { + return cloneDeep(drivers[driverId]); +} export function getTeam(teamId: TeamId): Team { return teams[teamId]; } +export function cloneTeam(teamId: TeamId): Team { + return cloneDeep(teams[teamId]); +} export function getTeamNumberStyle(teamId: TeamId): NumberStyle { return teamNumberStyles[teamId];