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.
This commit is contained in:
Kyle Geib committed 2022-01-28 17:53:50 -05:00
1 parent 8e4ac1243b
commit 5e7940a151
15 files changed
+266 -54

No files matched your search

@@ -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<Array<BGChyronMode>>(getChyronModesList());
const [chyronSubModes, setChyronSubModes] = useState<Array<BGChyronSubMode>>([]);
// Interface states.
const [chyronMode, setChyronMode] = useState<BGChyronMode>("driver");
const [chyronSubMode, setChyronSubMode] = useState<BGChyronSubMode>("medium");
const [posFlag, setPosFlag] = useState(true);
const [driverNum, setDriverNum] = useState(true);
const [portrait, setPortrait] = useState(false);
const [flagMode, setFlagMode] = useState<FlagMode>("country");
const dispatch = useDispatch();
const { chyrons } = useSelector(broadcastGraphicsSelector);
useEffect(() => {
setChyronSubModes(getChyronSubModesList(chyronMode));
}, [chyronMode]);
const onLaunch = () => {
const x = 0;
return x;
};
return (
<InlineCluster gutter="md">
<Title>Chyrons</Title>
<SlotContainer width={100}>
<SlotSelector
items={chyronModes}
onChange={index => setChyronMode(chyronModes[index])}
/>
</SlotContainer>
<SlotContainer width={100}>
<SlotSelector
items={chyronSubModes}
onChange={index => setChyronSubMode(chyronSubModes[index])}
/>
</SlotContainer>
<OpenButton
disabled={false}
>
<FaPlay size="0.8em" />
</OpenButton>
<Button
disabled={false}
>
<FaStepForward size="0.8em" />
</Button>
<CloseButton
disabled={false}
>
<FaStop size="0.8em" />
</CloseButton>
<Toggle
label="Pos. Flag"
toggled={posFlag}
onToggle={setPosFlag}
/>
<Toggle
label="Driver Num."
toggled={driverNum}
onToggle={setDriverNum}
/>
<Toggle
label="Portrait"
toggled={portrait}
onToggle={setPortrait}
/>
<SlotContainer width={200}>
<SlotSelector
label="Flag Mode"
items={flagModeList}
onChange={index => setFlagMode(flagModeList[index])}
/>
</SlotContainer>
</InlineCluster>
);
}
@@ -0,0 +1 @@
export * from "./ChyronsDirectorControls";
@@ -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<SlotContainerProps>`
width: ${({ width }) => `${width}px`};
`;
SlotContainer.displayName = "SlotContainer";
type ButtonProps = {
disabled: boolean,
};
export const Button = styled.button<ButtonProps>`
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)<ButtonProps>`
background-color: ${({ disabled }) => disabled
? p => p.theme.colors.disabledGreen : p => p.theme.colors.activeGreen};
`;
OpenButton.displayName = "OpenButton";
export const CloseButton = styled(Button)<ButtonProps>`
background-color: ${({ disabled }) => disabled
? p => p.theme.colors.disabledRed : p => p.theme.colors.activeRed};
`;
CloseButton.displayName = "CloseButton";
@@ -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<string>,
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 (
<SlotWindow onClick={onClick} disabled={disabled}>
{transitions((style, i) => (
<SlotText as={animated.span} style={style}>{getItem(i)}</SlotText>
))}
</SlotWindow>
<Inline gutter="sm" stretch="end" align="end">
{(label ?? null) && (
<SelectorLabel>{label}</SelectorLabel>
)}
<SlotWindow onClick={onClick} disabled={disabled}>
{transitions((style, i) => (
<SlotText as={animated.span} style={style}>{getItem(i)}</SlotText>
))}
</SlotWindow>
</Inline>
);
}
@@ -20,13 +20,21 @@ export const SlotWindow = styled.div<SlotWindowProps>`
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";
@@ -5,7 +5,7 @@ type ToggleContainerProps = {
}
export const ToggleContainer = styled.div<ToggleContainerProps>`
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<ToggleCircleProps>`
${({ toggled }) => toggled ? css`right: 0;` : css`left: 0;`}
`;
ToggleCircle.displayName = "ToggleCircle";
@@ -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 (
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
@@ -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 (
<Grid gutter="md">
<Split gutter="md">
<PadBox padding="md">
<ChyronControlsContainer>
<ChyronsDirectorControls />
</ChyronControlsContainer>
</PadBox>
<PadBox padding="md">
<GridSelection />
</PadBox>
<span>Launcher/Closer</span>
</Grid>
</Split>
);
}
@@ -0,0 +1,7 @@
import styled from "styled-components";
export const ChyronControlsContainer = styled.div`
width: 420px;
height: auto;
`;
ChyronControlsContainer.displayName = "ChyronControlsContainer";