From 5e7940a1512f909c8719c3efed4aa403d0817332 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Fri, 28 Jan 2022 17:53:50 -0500 Subject: [PATCH] ISSUE-032 - Progress checkpoint. Have a lot of the scaffolding in place. Next step is to make the Chyron controls actually work. Dramatic re-thinking of the chyron state definitions. Lots of goofy type following tricks in broadcastGraphics.ts. --- package.json | 1 + .../Chyrons/ChyronsDirectorControls.tsx | 94 +++++++++++++++++++ .../BroadcastDirectorUI/Chyrons/index.ts | 1 + .../BroadcastDirectorUI/Chyrons/styles.ts | 43 +++++++++ .../Inputs/SlotSelector/SlotSelector.tsx | 24 +++-- .../Common/Inputs/SlotSelector/styles.ts | 10 +- src/components/Common/Inputs/Toggle/styles.ts | 6 +- .../CustomWorkSpaces/AngledFlagWorkSpace.tsx | 12 +-- .../ChyronPrototypeControls.tsx | 14 ++- .../ChyronPrototype/styles.ts | 7 ++ src/domain/data/broadcastGraphics.ts | 42 +++++++++ .../graphics/broadcastGraphicsSlice.ts | 12 ++- src/shared/theme.ts | 7 ++ src/types/state.d.ts | 42 +++------ yarn.lock | 5 + 15 files changed, 266 insertions(+), 54 deletions(-) create mode 100644 src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx create mode 100644 src/components/Broadcast/BroadcastDirectorUI/Chyrons/index.ts create mode 100644 src/components/Broadcast/BroadcastDirectorUI/Chyrons/styles.ts create mode 100644 src/components/Workspaces/PrototypingControls/ChyronPrototype/styles.ts create mode 100644 src/domain/data/broadcastGraphics.ts diff --git a/package.json b/package.json index 1e02dbe..15f2b71 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "lodash": "^4.17.21", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-icons": "^4.3.1", "react-redux": "^7.2.6", "react-router-dom": "6", "react-scripts": "5.0.0", diff --git a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx new file mode 100644 index 0000000..e546fe3 --- /dev/null +++ b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx @@ -0,0 +1,94 @@ +import { InlineCluster } from "@bedrock-layout/inline-cluster"; +import { useEffect, useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; + +import { FaPlay, FaStepForward, FaStop } from "react-icons/fa"; +import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector"; + +import { flagModeList, getChyronModesList, getChyronSubModesList } from "../../../../domain/data/broadcastGraphics"; +import { BGChyronMode, BGChyronSubMode, FlagMode } from "../../../../types/state"; + +import { SlotSelector } from "../../../Common/Inputs/SlotSelector"; +import { Button, CloseButton, OpenButton, SlotContainer, Title } from "./styles"; +import { Toggle } from "../../../Common/Inputs/Toggle"; + +export function ChyronsDirectorControls() { + // Use state to prevent unnecessary resetting on re-renders. + const [chyronModes] = useState>(getChyronModesList()); + const [chyronSubModes, setChyronSubModes] = useState>([]); + + // Interface states. + const [chyronMode, setChyronMode] = useState("driver"); + const [chyronSubMode, setChyronSubMode] = useState("medium"); + const [posFlag, setPosFlag] = useState(true); + const [driverNum, setDriverNum] = useState(true); + const [portrait, setPortrait] = useState(false); + const [flagMode, setFlagMode] = useState("country"); + + const dispatch = useDispatch(); + const { chyrons } = useSelector(broadcastGraphicsSelector); + + useEffect(() => { + setChyronSubModes(getChyronSubModesList(chyronMode)); + }, [chyronMode]); + + const onLaunch = () => { + const x = 0; + return x; + }; + + return ( + + Chyrons + + setChyronMode(chyronModes[index])} + /> + + + setChyronSubMode(chyronSubModes[index])} + /> + + + + + + + + + + + + + setFlagMode(flagModeList[index])} + /> + + + ); +} diff --git a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/index.ts b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/index.ts new file mode 100644 index 0000000..e69fc02 --- /dev/null +++ b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/index.ts @@ -0,0 +1 @@ +export * from "./ChyronsDirectorControls"; diff --git a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/styles.ts b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/styles.ts new file mode 100644 index 0000000..75f02dc --- /dev/null +++ b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/styles.ts @@ -0,0 +1,43 @@ +import styled from "styled-components"; +import { Px } from "../../../../types/style"; + +export const Title = styled.h4` + font-family: ${p => p.theme.fonts.f1Italic}; +`; +Title.displayName = "Title"; + +type SlotContainerProps = { + width: Px, +}; +export const SlotContainer = styled.div` + width: ${({ width }) => `${width}px`}; +`; +SlotContainer.displayName = "SlotContainer"; + +type ButtonProps = { + disabled: boolean, +}; +export const Button = styled.button` + font-family: ${p => p.theme.fonts.f1Regular}; + color: ${({ disabled }) => disabled + ? p => p.theme.colors.grey : "black"}; + + background-color: ${p => p.theme.colors.lightGrey}; + border-radius: ${p => p.theme.design.button.borderRadius}; + border: 1px black solid; + + cursor: pointer; +`; +Button.displayName = "Button"; + +export const OpenButton = styled(Button)` + background-color: ${({ disabled }) => disabled + ? p => p.theme.colors.disabledGreen : p => p.theme.colors.activeGreen}; +`; +OpenButton.displayName = "OpenButton"; + +export const CloseButton = styled(Button)` + background-color: ${({ disabled }) => disabled + ? p => p.theme.colors.disabledRed : p => p.theme.colors.activeRed}; +`; +CloseButton.displayName = "CloseButton"; diff --git a/src/components/Common/Inputs/SlotSelector/SlotSelector.tsx b/src/components/Common/Inputs/SlotSelector/SlotSelector.tsx index 518a784..7472929 100644 --- a/src/components/Common/Inputs/SlotSelector/SlotSelector.tsx +++ b/src/components/Common/Inputs/SlotSelector/SlotSelector.tsx @@ -2,19 +2,26 @@ import { useEffect, useMemo, useState } from "react"; import { animated, useSpringRef, useTransition } from "@react-spring/web"; import { findPrefixCount } from "../../../../utils/strings"; -import { SlotText, SlotWindow } from "./styles"; +import { SelectorLabel, SlotText, SlotWindow } from "./styles"; +import { Inline } from "@bedrock-layout/inline"; type SlotSelectorProps = { items: Array, onChange: (index: number) => void, + label?: string, removePrefix?: boolean, formatter?: (value: string) => string, initialIndex?: number, disabled?: boolean, }; +/** + * If items are defined in a component make sure they are stateful to prevent + * random resets of the index during changes. + */ export function SlotSelector({ items, onChange, + label, removePrefix = false, formatter = (x) => x, initialIndex = 0, @@ -63,10 +70,15 @@ export function SlotSelector({ }, [index]); return ( - - {transitions((style, i) => ( - {getItem(i)} - ))} - + + {(label ?? null) && ( + {label} + )} + + {transitions((style, i) => ( + {getItem(i)} + ))} + + ); } diff --git a/src/components/Common/Inputs/SlotSelector/styles.ts b/src/components/Common/Inputs/SlotSelector/styles.ts index 9e2b68f..5996590 100644 --- a/src/components/Common/Inputs/SlotSelector/styles.ts +++ b/src/components/Common/Inputs/SlotSelector/styles.ts @@ -20,13 +20,21 @@ export const SlotWindow = styled.div` white-space: nowrap; text-overflow: ellipsis; `; +SlotWindow.displayName = "SlotWindow"; export const SlotText = styled.span` position: absolute; display: block; margin-left: .4em; font-family: ${p => p.theme.fonts.f1Regular}; - font-size: 0.9em; + font-size: ${p => p.theme.fontSizes.selector}; color: ${p => p.theme.colors.darkGrey}; user-select: none; `; +SlotText.displayName = "SlotText"; + +export const SelectorLabel = styled.span` + font-family: ${p => p.theme.fonts.f1Regular}; + font-size: ${p => p.theme.fontSizes.label}; +`; +SelectorLabel.displayName = "SelectorLabel"; diff --git a/src/components/Common/Inputs/Toggle/styles.ts b/src/components/Common/Inputs/Toggle/styles.ts index e51a11b..5be4f32 100644 --- a/src/components/Common/Inputs/Toggle/styles.ts +++ b/src/components/Common/Inputs/Toggle/styles.ts @@ -5,7 +5,7 @@ type ToggleContainerProps = { } export const ToggleContainer = styled.div` display: flex; - justify-content: center; + align-items: flex-end; font-size: ${({ fontSize = "inherit" }) => fontSize}; `; ToggleContainer.displayName = "ToggleContainer"; @@ -24,7 +24,10 @@ ToggleInput.displayName = "ToggleInput"; export const ToggleLabelText = styled.span` margin-right: 1ch; + font-family: ${p => p.theme.fonts.f1Regular}; + font-size: ${p => p.theme.fontSizes.label}; `; +ToggleLabelText.displayName = "ToggleLabelText"; export const ToggleLabel = styled.label` display: block; @@ -95,4 +98,3 @@ export const ToggleCircle = styled.div` ${({ toggled }) => toggled ? css`right: 0;` : css`left: 0;`} `; ToggleCircle.displayName = "ToggleCircle"; - diff --git a/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx b/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx index 23d1d35..08ecf83 100644 --- a/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx +++ b/src/components/Workspaces/CustomWorkSpaces/AngledFlagWorkSpace.tsx @@ -1,5 +1,4 @@ -import { useEffect } from "react"; -import { useDispatch, useSelector } from "react-redux"; +import { useSelector } from "react-redux"; import { workspaceSelector } from "../../../features/workspace/workspaceSelector"; @@ -9,15 +8,6 @@ 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/ChyronPrototype/ChyronPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/ChyronPrototype/ChyronPrototypeControls.tsx index d37a04b..9f22149 100644 --- a/src/components/Workspaces/PrototypingControls/ChyronPrototype/ChyronPrototypeControls.tsx +++ b/src/components/Workspaces/PrototypingControls/ChyronPrototype/ChyronPrototypeControls.tsx @@ -1,15 +1,21 @@ -import { Grid } from "@bedrock-layout/grid"; import { PadBox } from "@bedrock-layout/padbox"; +import { Split } from "@bedrock-layout/split"; +import { ChyronsDirectorControls } from "../../../Broadcast/BroadcastDirectorUI/Chyrons"; import { GridSelection } from "../GridSelection"; +import { ChyronControlsContainer } from "./styles"; export function ChyronPrototypeControls() { return ( - + + + + + + - Launcher/Closer - + ); } diff --git a/src/components/Workspaces/PrototypingControls/ChyronPrototype/styles.ts b/src/components/Workspaces/PrototypingControls/ChyronPrototype/styles.ts new file mode 100644 index 0000000..6f0499e --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/ChyronPrototype/styles.ts @@ -0,0 +1,7 @@ +import styled from "styled-components"; + +export const ChyronControlsContainer = styled.div` + width: 420px; + height: auto; +`; +ChyronControlsContainer.displayName = "ChyronControlsContainer"; diff --git a/src/domain/data/broadcastGraphics.ts b/src/domain/data/broadcastGraphics.ts new file mode 100644 index 0000000..05940ce --- /dev/null +++ b/src/domain/data/broadcastGraphics.ts @@ -0,0 +1,42 @@ +import { keys } from "lodash"; +import { BGChyronSubMode, BGChyronMode, BGRelativePos, FlagMode } from "../../types/state"; + +// Chyrons Section +const chyronsData: { + [mode: BGChyronMode]: { + relativePos: BGRelativePos, + subModes: { + [subMode: BGChyronSubMode]: Record, + }, + }, +} = { + driver: { + relativePos: { top: "0", right: "0", bottom: "0", left: "0" }, + subModes: { + medium: { width: 582, height: 72 }, + large: { width: 638, height: 98 }, + }, + }, +}; + +export const flagModeList: Array = ["country", "team", "none"]; + +export function getChyronModesList(): Array { + return keys(chyronsData); +} + +export function getChyronRelativePos(mode: BGChyronMode): BGRelativePos { + return chyronsData[mode]?.relativePos + ?? { top: "0", right: "0", bottom: "0", left: "0" }; +} + +export function getChyronSubModesList(mode: BGChyronMode): Array { + return keys(chyronsData[mode]?.subModes ?? {}); +} + +export function getChyronSubModeProps( + mode: BGChyronMode, + subMode: BGChyronSubMode, +): Record { + return chyronsData[mode]?.subModes[subMode] ?? {}; +} diff --git a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts index 617acd4..0d8be0b 100644 --- a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts +++ b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts @@ -13,7 +13,7 @@ export const broadcastGraphicsSlice = createSlice({ chyronsLaunch: (state, action: PayloadAction) => { state.chyrons = action.payload; }, - chyronsSetOpenState: (state, action: PayloadAction) => { + chyronsOpenStateSet: (state, action: PayloadAction) => { if (state.chyrons == null) return; state.chyrons.primary.openState = action.payload; @@ -21,6 +21,14 @@ export const broadcastGraphicsSlice = createSlice({ state.chyrons.secondary.openState = action.payload; } }, + chyronsOpenStateIncrement: (state) => { + if (state.chyrons == null) return; + ++state.chyrons.primary.openState; + + if (state.chyrons.secondary != null) { + ++state.chyrons.secondary.openState; + } + }, chyronsClear: (state) => { state.chyrons = null; }, @@ -29,6 +37,8 @@ export const broadcastGraphicsSlice = createSlice({ export const { chyronsLaunch, + chyronsOpenStateSet, + chyronsOpenStateIncrement, chyronsClear, } = broadcastGraphicsSlice.actions; export default broadcastGraphicsSlice.reducer; diff --git a/src/shared/theme.ts b/src/shared/theme.ts index 755e588..019b999 100644 --- a/src/shared/theme.ts +++ b/src/shared/theme.ts @@ -15,6 +15,9 @@ export const theme = { blue: "#387af5", pink: "#eb57a3", activeGreen: "#65c466", + disabledGreen: "#b1d3b2", + activeRed: "#e63746", + disabledRed: "#e08a91", grey: "#aaa", lightGrey: "#ddd", faintGrey: "#eee", @@ -33,6 +36,10 @@ export const theme = { williams: "#005aff", }, }, + fontSizes: { + label: "0.9em", + selector: "0.9em", + }, design: { button: { borderRadius: "0.25rem", diff --git a/src/types/state.d.ts b/src/types/state.d.ts index 9850297..4f083e1 100644 --- a/src/types/state.d.ts +++ b/src/types/state.d.ts @@ -195,7 +195,7 @@ export interface BGBaseState { openState: OpenState; } /** - * -1 closing, 0 closed, 1 open, 2... different states + * -1 closing, 0 closed, 1 open, 2... different states (for progressive anims) */ export type OpenState = number; @@ -209,40 +209,24 @@ export interface BroadcastGraphics { } // Chyrons -export type FlagMode = "country" | "team"; -export type BGChyronMode = - | "driver-basic-small" - | "driver-basic-medium" - | "driver-basic-large"; +export type BGChyronMode = string; +export type BGChyronSubMode = string; export interface BGChyron extends BGBaseState { mode: BGChyronMode; - car: Car; - flagMode: FlagMode; - showPosFlag: boolean; - showDriverNumber: boolean; - dimensions: Dimensions; - props?: unknown; } export interface BGChyrons { primary: BGChyron; secondary: Optional; // sponsorGem: BGSponsorGem; } -export interface BGChyronMedium extends BGChyron { - mode: "driver-basic-medium"; - dimensions: { - width: 582; - height: 72; - } - props: { - showPortrait: boolean; - } -} -export interface BGChyronLarge extends BGChyron { - mode: "driver-basic-large"; - dimensions: { - width: 638; - height: 98; - } -} +export type FlagMode = "country" | "team" | "none"; +export interface BGChyronDriver extends BGChyron { + car: Car; + subMode: BGChyronSubMode; + baseDimensions: Dimensions; + flagMode: FlagMode; + showPosFlag: boolean; + showDriverNumber: boolean; + showPortrait: boolean; +} diff --git a/yarn.lock b/yarn.lock index b665779..b3da133 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7726,6 +7726,11 @@ react-error-overlay@^6.0.10: resolved "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.10.tgz" integrity sha512-mKR90fX7Pm5seCOfz8q9F+66VCc1PGsWSBxKbITjfKVQHMNF2zudxHnMdJiB1fRCb+XsbQV9sO9DCkgsMQgBIA== +react-icons@^4.3.1: + version "4.3.1" + resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.3.1.tgz#2fa92aebbbc71f43d2db2ed1aed07361124e91ca" + integrity sha512-cB10MXLTs3gVuXimblAdI71jrJx8njrJZmNMEMC+sQu5B/BIOmlsAjskdqpn81y8UBVEGuHODd7/ci5DvoSzTQ== + react-is@^16.7.0, react-is@^16.8.1: version "16.13.1" resolved "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz"