ISSUE-032 - Progress checkpoint. Have a working "selectedCars" modifying component named GridSelection.

Have a work-in-progress AngledFlag prototype controller that relying on a central state property in the Workspaces portion of the store. It's a bit hacky. But it made me realize that my desire to do silly things with extending interfaces won't work that way I'm going to need to rely on them in the future. I cannot demand more specific data from a state that uses a less specific interface. Rookie mistake.
I am also at the mercy of a design flaw when it comes to using React Hooks: The way I organize Workspaces makes React very angry. When I switch between workspaces that rely on hooks to render correctly the whole thing explodes.

I believe I need to use components directly to correctly unmount - instead of the very hacky switch statement I have in the form of fetchBroadcastGraphic().

I might need to try seeing if ReactRouter can provide my solution.
This commit is contained in:
Kyle Geib committed 2022-01-27 17:47:49 -05:00
1 parent 5d009a3d70
commit e676c7a95a
17 files changed
+247 -33

No files matched your search

@@ -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 (
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
<AngledFlag
flagMode="country"
flag="GBR"
flag={prototypeState?.angledFlag?.flagA ?? "GBR"}
flagHeight={64}
/>
<AngledFlag
flagMode="country"
flag="MEX"
flag={prototypeState?.angledFlag?.flagB ?? "GBR"}
flagHeight={128}
/>
</BasicBlock>
@@ -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 (
<Split as={PadBox} gutter="md" padding="md">
<SlotSelector items={countries} onChange={onChange("flagA")}/>
<SlotSelector items={countries} onChange={onChange("flagB")}/>
</Split>
);
}
@@ -0,0 +1 @@
export * from "./AngledFlagPrototypeControls";
@@ -0,0 +1,15 @@
import { Grid } from "@bedrock-layout/grid";
import { PadBox } from "@bedrock-layout/padbox";
import { GridSelection } from "../GridSelection";
export function ChyronPrototypeControls() {
return (
<Grid gutter="md">
<PadBox padding="md">
<GridSelection />
</PadBox>
<span>Launcher/Closer</span>
</Grid>
);
}
@@ -0,0 +1 @@
export * from "./ChyronPrototypeControls";
@@ -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 (
<InlineCluster gutter="xs">
{grid.map(car => {
const selectedIndex = findIndex(selectedCars, carMatch(car));
const selected = selectedIndex !== -1;
const onClick = carClick(car, selected);
const onDoubleClick = carDoubleClick(car);
return (
<GridItem
key={car.driver.id}
selected={selected}
onClick={onClick}
onDoubleClick={onDoubleClick}
>
<DriverLabel>
{car.driver.initials}
</DriverLabel>
{selected && (
<SelectionLabel>{selectedIndex + 1}</SelectionLabel>
)}
</GridItem>
);
})}
</InlineCluster>
);
}
@@ -0,0 +1 @@
export * from "./GridSelection";
@@ -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"],
}))<GridItemProps>`
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;
`;