ISSUE-035 - Took some work but have proper type checking for AngledFlag props and have updated everything necessary.

Styling is still to come. Only have Ferrari working.
I've discovered that the team flags are wider than the country flags. So I'll be tackling that necessary change in the next commit before dealing with styling.
This commit is contained in:
Kyle Geib committed 2022-02-01 12:57:40 -05:00
1 parent 57647f6488
commit bd1892ab17
9 files changed
+231 -53

No files matched your search

@@ -29,6 +29,9 @@ export function ChyronDriver({ chyronData, subMode }: ChyronDriverProps) {
: [0, 0];
const { car, flagMode, showPosFlag, showDriverNumber } = chyronData;
const flagProps = flagMode === "country"
? { flagMode, flag: car.driver.nationality }
: flagMode === "team" ? { flagMode, flag: car.driver.team.id } : undefined;
return (
<BaseBackground width={baseWidth} height={baseHeight}>
@@ -64,11 +67,12 @@ export function ChyronDriver({ chyronData, subMode }: ChyronDriverProps) {
width={baseHeight * 3}
right={-baseHeight * 0.6}
>
<AngledFlag
flagMode={flagMode}
flag={car.driver.nationality}
flagHeight={baseHeight * 0.9}
/>
{flagProps != null && (
<AngledFlag
flagHeight={baseHeight * 0.9}
flagProps={flagProps}
/>
)}
</FlagContainer>
</BaseBackground>
);
@@ -1,16 +1,19 @@
import { FlagMode } from "../../../../types/state";
import { ReactNode } from "react";
import { TeamId } from "../../../../types/state";
import { Px } from "../../../../types/style";
import { getTeamFlagStyle } from "../../../../utils/dataLookup";
import {
Container,
Slant,
Sheen,
CountryFlagEdge,
FlagEdge,
CountryFlagDiv,
FlagContainer,
TeamFlagDiv,
} from "./styles";
const countryFlags = require.context("../../../../public/images/countryFlags/angled", true);
// const teamLogos = require.context("../../../../public/images/teamLogos", true);
const teamLogos = require.context("../../../../public/images/logos/team", true);
/**
* To look right, country flags need to be 2:1. Additional editing will be
@@ -19,35 +22,67 @@ const countryFlags = require.context("../../../../public/images/countryFlags/ang
* center.
*/
type AngledFlagProps = {
flagMode: FlagMode,
flag: string,
flagHeight: Px,
flagProps: {
flagMode: "country",
flag: string,
} | {
flagMode: "team",
flag: TeamId,
},
};
export function AngledFlag({ flagMode, flag, flagHeight }: AngledFlagProps) {
const topFlag = flagMode === "country"
? (
export function AngledFlag(props: AngledFlagProps) {
const { flagProps, flagHeight } = props;
let topFlag: ReactNode = null;
let bottomFlag: ReactNode = null;
if (flagProps.flagMode === "country") {
topFlag = (
<CountryFlagDiv
src={countryFlags(`./${flag}.svg`)}
src={countryFlags(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
>
<CountryFlagEdge
<FlagEdge
x={flagHeight / 2}
height={flagHeight}
girth={flagHeight * 0.07}
/>
</CountryFlagDiv>
) : null; // Team flag here
const bottomFlag = flagMode === "country"
? (
);
bottomFlag = (
<CountryFlagDiv
src={countryFlags(`./${flag}.svg`)}
src={countryFlags(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
xOffset={-flagHeight * 0.005}
/>
) : null; // Team flag here
);
} else if (flagProps.flagMode === "team") {
topFlag = (
<TeamFlagDiv
src={teamLogos(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
style={getTeamFlagStyle(flagProps.flag)}
>
<FlagEdge
x={flagHeight / 2}
height={flagHeight}
girth={flagHeight * 0.07}
/>
</TeamFlagDiv>
);
bottomFlag = (
<TeamFlagDiv
src={teamLogos(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
style={getTeamFlagStyle(flagProps.flag)}
/>
);
}
return (
<Container width={flagHeight * 6} height={flagHeight * 3}>
@@ -1,4 +1,5 @@
import styled, { css } from "styled-components";
import { TeamFlagStyle } from "../../../../domain/data/teams";
import { Px } from "../../../../types/style";
type ContainerProps = {
@@ -68,24 +69,48 @@ export const FlagContainer = styled.div<FlagContainerProps>`
`;
FlagContainer.displayName = "FlagContainer";
type CountryFlagDivProps = {
type FlagDivBaseProps = {
src: string,
height: Px,
width: Px,
xOffset?: Px,
};
export const CountryFlagDiv = styled.div<CountryFlagDivProps>`
const FlagDivBase = styled.div<FlagDivBaseProps>`
height: ${({ height }) => `${height}px`};
width: ${({ width }) => `${width}px`};
background-image: url(${({ src }) => src});
background-size: ${({ width, height }) => `${width}px ${height}px`};
background-repeat: no-repeat;
`;
type CountryFlagDivProps = {
xOffset?: Px,
};
export const CountryFlagDiv = styled(FlagDivBase)<CountryFlagDivProps>`
background-size: ${({ width, height }) => `${width}px ${height}px`};
${({ xOffset }) => xOffset == null
? css`background-position: center;`
: css`background-position-x: ${xOffset}px`}
`;
CountryFlagDiv.displayName = "CountryFlagDiv";
type TeamFlagDivProps = {
style: TeamFlagStyle,
};
export const TeamFlagDiv = styled(FlagDivBase) <TeamFlagDivProps>`
height: ${({ height }) => `${height}px`};
width: ${({ width }) => `${width}px`};
background-image: url(${({ src }) => src})
${({ style: { backgroundImage } }) => backgroundImage
&& `, background-image: ${backgroundImage}`};
background-size: ${({ style: { imageSize } }) => `${imageSize}%`};
background-position: ${({ style: { imagePos: { x, y } } }) => `${x}% ${y}%`};
${({ style: { backgroundColor } }) => backgroundColor &&
css`background-color: ${backgroundColor};`}
${({ style: { backgroundImage } }) => backgroundImage &&
css`background-image: ${backgroundImage};`}
`;
type SlashProps = {
x?: Px,
height: Px,
@@ -126,7 +151,7 @@ export const Slant = styled.div<SlashProps>`
`;
Slant.displayName = "Slant";
export const CountryFlagEdge = styled.div<SlashProps>`
export const FlagEdge = styled.div<SlashProps>`
position: absolute;
height: ${({ height }) => `${height}px`};
width: ${({ girth }) => `${girth}px`};
@@ -142,4 +167,4 @@ export const CountryFlagEdge = styled.div<SlashProps>`
black 100%
);
`;
CountryFlagEdge.displayName = "CountryFlagEdge";
FlagEdge.displayName = "FlagEdge";
@@ -1,7 +1,7 @@
import { useSelector } from "react-redux";
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
import { FlagMode } from "../../../types/state";
import { FlagMode, TeamId } from "../../../types/state";
import { AngledFlag } from "../../BroadcastGraphics/Common/AngledFlag";
import { BasicBlock } from "./styles";
@@ -11,20 +11,48 @@ type AngledFlagWorkSpaceProps = {
};
export function AngledFlagWorkSpace({ flagMode }: AngledFlagWorkSpaceProps) {
const { prototypeState } = useSelector(workspaceSelector);
const defaultFlag = flagMode === "country" ? "GBR" : flagMode === "team" ? "alpine" : "";
if (flagMode === "none") return null;
const defaultTeam: TeamId = "alpine";
return (
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
<AngledFlag
flagMode={flagMode}
flag={prototypeState?.angledFlag?.flagA ?? defaultFlag}
flagHeight={64}
/>
<AngledFlag
flagMode={flagMode}
flag={prototypeState?.angledFlag?.flagB ?? defaultFlag}
flagHeight={128}
/>
{flagMode === "country" ? (
<>
<AngledFlag
flagProps={{
flagMode,
flag: prototypeState?.angledFlagCountry?.flagA ?? "GBR",
}}
flagHeight={64}
/>
<AngledFlag
flagProps={{
flagMode,
flag: prototypeState?.angledFlagCountry?.flagB ?? "GBR",
}}
flagHeight={128}
/>
</>
) : flagMode === "team" ? (
<>
<AngledFlag
flagProps={{
flagMode,
flag: prototypeState?.angledFlagTeam?.flagA ?? defaultTeam,
}}
flagHeight={64}
/>
<AngledFlag
flagProps={{
flagMode,
flag: prototypeState?.angledFlagTeam?.flagB ?? defaultTeam,
}}
flagHeight={128}
/>
</>
) : null}
</BasicBlock>
);
}
@@ -26,12 +26,22 @@ export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeCon
const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : [];
const onChange = (flag: "flagA" | "flagB") => (index: number) => {
dispatch(setPrototypeState({
angledFlag: {
flagA: flag === "flagA" ? flagList[index] : prototypeState?.angledFlag?.flagA ?? "GBR",
flagB: flag === "flagB" ? flagList[index] : prototypeState?.angledFlag?.flagB ?? "GBR",
},
}));
if (flagMode === "country") {
dispatch(setPrototypeState({
angledFlagCountry: {
flagA: flag === "flagA" ? countries[index] : prototypeState?.angledFlagCountry?.flagA ?? "GBR",
flagB: flag === "flagB" ? countries[index] : prototypeState?.angledFlagCountry?.flagB ?? "GBR",
},
}));
} else if (flagMode === "team") {
dispatch(setPrototypeState({
angledFlagTeam: {
flagA: flag === "flagA" ? teams[index] : prototypeState?.angledFlagTeam?.flagA ?? "alpine",
flagB: flag === "flagB" ? teams[index] : prototypeState?.angledFlagTeam?.flagB ?? "alpine",
},
}));
}
};
return (
<Split as={PadBox} gutter="md" padding="md">