diff --git a/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx b/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx index b8cb17b..2638c2b 100644 --- a/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx +++ b/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { useSpring, animated, config } from "@react-spring/web"; +import { useSpring, animated } from "@react-spring/web"; import useMeasure from "react-use-measure"; import { VenetianBlindsFilter } from "./styles"; @@ -8,15 +8,17 @@ import { Corner } from "../../../../types/style"; type VenetianBlindsTransitionProps = { blindsColor: string, - degrees: number, - duration: number, + blindsAngle: number, + wipeAngle: number, + wipeDuration: number, wipeStartingCorner: Corner, }; export const VenetianBlindsTransition = ( { blindsColor, - degrees, - duration, + blindsAngle, + wipeAngle, + wipeDuration, wipeStartingCorner, children, }: React.PropsWithChildren, @@ -28,30 +30,30 @@ export const VenetianBlindsTransition = ( const [state, toggle] = useState(true); - const { x } = useSpring({ - from: { x: 0 }, - x: state ? 1 : 0, - config: { duration }, + const { wipe } = useSpring({ + from: { wipe: 0 }, + wipe: state ? 1 : 0, + config: { duration: wipeDuration }, }); return (
toggle(!state)}> { + clipPath: wipe.to(wipeProgress => { const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip( childWidth, childHeight, - x, + wipeProgress, wipeStartingCorner, - degrees, + wipeAngle, ); return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`; }), }} > diff --git a/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/AngledFlagPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/AngledFlagPrototypeControls.tsx index 82c0baf..dbaa0fa 100644 --- a/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/AngledFlagPrototypeControls.tsx +++ b/src/components/Workspaces/PrototypingControls/AngledFlagPrototype/AngledFlagPrototypeControls.tsx @@ -1,9 +1,8 @@ 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 { useDispatch } from "react-redux"; -import { setPrototypeState } from "../../../../features/workspace/workspaceSlice"; +import { updateAngledFlagCountry, updateAngledFlagTeam } from "../../../../features/workspace/workspaceSlice"; import { FlagMode, TeamId } from "../../../../types/state"; import { SlotSelector } from "../../../Common/Inputs/SlotSelector"; @@ -17,41 +16,22 @@ const teams: Array = [ "mclaren", "mercedes", "redBull", "williams", ]; -const DEFAULT_COUNTRY = "GBR"; -const DEFAULT_TEAM: TeamId = "alfaRomeo"; - type AngledFlagPrototypeControlsProps = { flagMode: FlagMode, }; export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeControlsProps) { const dispatch = useDispatch(); - const { prototypeState } = useSelector(workspaceSelector); const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : []; const onChange = (flag: "flagA" | "flagB") => (index: number) => { if (flagMode === "country") { - dispatch(setPrototypeState({ - angledFlagCountry: { - flagA: flag === "flagA" - ? countries[index] - : prototypeState?.angledFlagCountry?.flagA ?? DEFAULT_COUNTRY, - flagB: flag === "flagB" - ? countries[index] - : prototypeState?.angledFlagCountry?.flagB ?? DEFAULT_COUNTRY, - }, + dispatch(updateAngledFlagCountry({ + [flag]: countries[index], })); } else if (flagMode === "team") { - dispatch(setPrototypeState({ - angledFlagTeam: { - flagA: flag === "flagA" - ? teams[index] - : prototypeState?.angledFlagTeam?.flagA ?? DEFAULT_TEAM, - flagB: flag === "flagB" - ? teams[index] - : prototypeState?.angledFlagTeam?.flagB ?? DEFAULT_TEAM, - }, + dispatch(updateAngledFlagTeam({ + [flag]: teams[index], })); - } }; return ( diff --git a/src/components/Workspaces/PrototypingControls/VenetianBlindsPrototype/VenetianBlindsPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/VenetianBlindsPrototype/VenetianBlindsPrototypeControls.tsx index 51c8379..65e8980 100644 --- a/src/components/Workspaces/PrototypingControls/VenetianBlindsPrototype/VenetianBlindsPrototypeControls.tsx +++ b/src/components/Workspaces/PrototypingControls/VenetianBlindsPrototype/VenetianBlindsPrototypeControls.tsx @@ -1,8 +1,9 @@ import { InlineCluster } from "@bedrock-layout/inline-cluster"; import { PadBox } from "@bedrock-layout/padbox"; import { useDispatch, useSelector } from "react-redux"; + import { workspaceSelector } from "../../../../features/workspace/workspaceSelector"; -import { setPrototypeState } from "../../../../features/workspace/workspaceSlice"; +import { updateVenetianTransition } from "../../../../features/workspace/workspaceSlice"; import { VenetianTransitionWorkspaceMode } from "../../../../types/state"; import { SlotSelector } from "../../../Common/Inputs/SlotSelector"; @@ -18,20 +19,14 @@ export function VenetianBlindsPrototypeControls() { const { prototypeState } = useSelector(workspaceSelector); const onChange = (index: number) => { - dispatch(setPrototypeState({ - venetianTransition: { - mode: modes[index], - showBG: prototypeState?.venetianTransition?.showBG ?? false, - }, + dispatch(updateVenetianTransition({ + mode: modes[index], })); }; const onToggle = (value: boolean) => { - dispatch(setPrototypeState({ - venetianTransition: { - mode: prototypeState?.venetianTransition?.mode ?? "positionFlag", - showBG: value, - }, + dispatch(updateVenetianTransition({ + showBG: value, })); }; @@ -44,7 +39,7 @@ export function VenetianBlindsPrototypeControls() { slotWidth="200px" /> diff --git a/src/features/workspace/workspaceSlice.ts b/src/features/workspace/workspaceSlice.ts index 417a956..21a24d0 100644 --- a/src/features/workspace/workspaceSlice.ts +++ b/src/features/workspace/workspaceSlice.ts @@ -9,7 +9,7 @@ const initialState: RootState["workspace"] = { overlayIds: [], previewWindowDimensions: { width: 0, height: 0 }, }, - prototypeState: null, + prototypeState: {}, }; export type UpdateWorkspaceAction = { @@ -31,8 +31,54 @@ export const workspaceSlice = createSlice({ state.workspaceId = action.payload.workspaceId; state.workspaceProperties = action.payload.workspaceProperties; }, - setPrototypeState: (state, action: PayloadAction) => { - state.prototypeState = action.payload; + + // Prototype States + updateAngledFlagCountry: ( + state, + action: PayloadAction>, + ) => { + if (state.prototypeState.angledFlagCountry == null) { + state.prototypeState.angledFlagCountry = { + flagA: "GBR", + flagB: "GBR", + }; + } + state.prototypeState.angledFlagCountry = Object.assign( + state.prototypeState.angledFlagCountry, + action.payload, + ); + }, + updateAngledFlagTeam: ( + state, + action: PayloadAction>, + ) => { + if (state.prototypeState.angledFlagTeam == null) { + state.prototypeState.angledFlagTeam = { + flagA: "alfaRomeo", + flagB: "alfaRomeo", + }; + } + state.prototypeState.angledFlagTeam = Object.assign( + state.prototypeState.angledFlagTeam, + action.payload, + ); + }, + updateVenetianTransition: ( + state, + action: PayloadAction>, + ) => { + if (state.prototypeState.venetianTransition == null) { + state.prototypeState.venetianTransition = { + mode: "positionFlag", + showBG: true, + timing: 500, + startingCorner: "topLeft", + }; + } + state.prototypeState.venetianTransition = Object.assign( + state.prototypeState?.venetianTransition, + action.payload, + ); }, }, }); @@ -41,6 +87,8 @@ export const { setWorkspaceId, setAnimatedBG, updateWorkspace, - setPrototypeState, + updateAngledFlagCountry, + updateAngledFlagTeam, + updateVenetianTransition, } = workspaceSlice.actions; export default workspaceSlice.reducer; diff --git a/src/types/state.d.ts b/src/types/state.d.ts index fcab41a..d931dba 100644 --- a/src/types/state.d.ts +++ b/src/types/state.d.ts @@ -1,4 +1,5 @@ import { Milliseconds, Optional } from "./util"; +import { Corner } from "./style"; export interface RootState { pageDimensions: PageDimensions; @@ -22,7 +23,7 @@ export interface Workspace { workspaceId: WorkspaceId; animatedBG: boolean; workspaceProperties: WorkspaceProperties; - prototypeState: Optional; + prototypeState: PrototypeState; } export type WorkspaceId = string; @@ -43,6 +44,8 @@ export interface PrototypeState { venetianTransition?: { mode: VenetianTransitionWorkspaceMode; showBG: boolean; + timing: number, + startingCorner: Corner, }; } export type VenetianTransitionWorkspaceMode = "positionFlag" | "driverPortrait";