ISSUE-045 - Venetian Blinds - Improvements to prototype state management by using partial state updates, which are pretty useful.
More props for <VenentianBlindsTransition>.
This commit is contained in:
1 parent
14e4c0569d
commit
3ce590d794
6 files changed
+88
-58
No files matched your search
+15
-13
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from "react";
|
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 useMeasure from "react-use-measure";
|
||||||
|
|
||||||
import { VenetianBlindsFilter } from "./styles";
|
import { VenetianBlindsFilter } from "./styles";
|
||||||
@@ -8,15 +8,17 @@ import { Corner } from "../../../../types/style";
|
|||||||
|
|
||||||
type VenetianBlindsTransitionProps = {
|
type VenetianBlindsTransitionProps = {
|
||||||
blindsColor: string,
|
blindsColor: string,
|
||||||
degrees: number,
|
blindsAngle: number,
|
||||||
duration: number,
|
wipeAngle: number,
|
||||||
|
wipeDuration: number,
|
||||||
wipeStartingCorner: Corner,
|
wipeStartingCorner: Corner,
|
||||||
};
|
};
|
||||||
export const VenetianBlindsTransition = (
|
export const VenetianBlindsTransition = (
|
||||||
{
|
{
|
||||||
blindsColor,
|
blindsColor,
|
||||||
degrees,
|
blindsAngle,
|
||||||
duration,
|
wipeAngle,
|
||||||
|
wipeDuration,
|
||||||
wipeStartingCorner,
|
wipeStartingCorner,
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
}: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
||||||
@@ -28,30 +30,30 @@ export const VenetianBlindsTransition = (
|
|||||||
|
|
||||||
const [state, toggle] = useState(true);
|
const [state, toggle] = useState(true);
|
||||||
|
|
||||||
const { x } = useSpring({
|
const { wipe } = useSpring({
|
||||||
from: { x: 0 },
|
from: { wipe: 0 },
|
||||||
x: state ? 1 : 0,
|
wipe: state ? 1 : 0,
|
||||||
config: { duration },
|
config: { duration: wipeDuration },
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={() => toggle(!state)}>
|
<div onClick={() => toggle(!state)}>
|
||||||
<animated.div
|
<animated.div
|
||||||
style={{
|
style={{
|
||||||
clipPath: x.to(x => {
|
clipPath: wipe.to(wipeProgress => {
|
||||||
const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip(
|
const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip(
|
||||||
childWidth,
|
childWidth,
|
||||||
childHeight,
|
childHeight,
|
||||||
x,
|
wipeProgress,
|
||||||
wipeStartingCorner,
|
wipeStartingCorner,
|
||||||
degrees,
|
wipeAngle,
|
||||||
);
|
);
|
||||||
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<VenetianBlindsFilter
|
<VenetianBlindsFilter
|
||||||
deg={-45}
|
deg={blindsAngle}
|
||||||
transparentWidth={3}
|
transparentWidth={3}
|
||||||
opaqueWidth={5}
|
opaqueWidth={5}
|
||||||
opaqueColor={blindsColor}
|
opaqueColor={blindsColor}
|
||||||
|
|||||||
+6
-4
@@ -17,8 +17,9 @@ export function VenetianBlindsWorkspace() {
|
|||||||
{prototypeState?.venetianTransition?.mode === "driverPortrait" ? (
|
{prototypeState?.venetianTransition?.mode === "driverPortrait" ? (
|
||||||
<VenetianBlindsTransition
|
<VenetianBlindsTransition
|
||||||
blindsColor={theme.colors.teams.mercedes + "b5"}
|
blindsColor={theme.colors.teams.mercedes + "b5"}
|
||||||
degrees={35}
|
blindsAngle={-45}
|
||||||
duration={500}
|
wipeAngle={45}
|
||||||
|
wipeDuration={500}
|
||||||
wipeStartingCorner="topLeft"
|
wipeStartingCorner="topLeft"
|
||||||
>
|
>
|
||||||
<DriverPortrait
|
<DriverPortrait
|
||||||
@@ -29,8 +30,9 @@ export function VenetianBlindsWorkspace() {
|
|||||||
) : (
|
) : (
|
||||||
<VenetianBlindsTransition
|
<VenetianBlindsTransition
|
||||||
blindsColor="#f60d0db5"
|
blindsColor="#f60d0db5"
|
||||||
degrees={45}
|
blindsAngle={-45}
|
||||||
duration={350}
|
wipeAngle={35}
|
||||||
|
wipeDuration={350}
|
||||||
wipeStartingCorner="bottomRight"
|
wipeStartingCorner="bottomRight"
|
||||||
>
|
>
|
||||||
<PositionFlag size={122} number={1} />
|
<PositionFlag size={122} number={1} />
|
||||||
|
|||||||
+6
-26
@@ -1,9 +1,8 @@
|
|||||||
import { PadBox } from "@bedrock-layout/padbox";
|
import { PadBox } from "@bedrock-layout/padbox";
|
||||||
import { Split } from "@bedrock-layout/split";
|
import { Split } from "@bedrock-layout/split";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
|
|
||||||
|
|
||||||
import { setPrototypeState } from "../../../../features/workspace/workspaceSlice";
|
import { updateAngledFlagCountry, updateAngledFlagTeam } from "../../../../features/workspace/workspaceSlice";
|
||||||
import { FlagMode, TeamId } from "../../../../types/state";
|
import { FlagMode, TeamId } from "../../../../types/state";
|
||||||
|
|
||||||
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
|
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
|
||||||
@@ -17,41 +16,22 @@ const teams: Array<TeamId> = [
|
|||||||
"mclaren", "mercedes", "redBull", "williams",
|
"mclaren", "mercedes", "redBull", "williams",
|
||||||
];
|
];
|
||||||
|
|
||||||
const DEFAULT_COUNTRY = "GBR";
|
|
||||||
const DEFAULT_TEAM: TeamId = "alfaRomeo";
|
|
||||||
|
|
||||||
type AngledFlagPrototypeControlsProps = {
|
type AngledFlagPrototypeControlsProps = {
|
||||||
flagMode: FlagMode,
|
flagMode: FlagMode,
|
||||||
};
|
};
|
||||||
export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeControlsProps) {
|
export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeControlsProps) {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { prototypeState } = useSelector(workspaceSelector);
|
|
||||||
const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : [];
|
const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : [];
|
||||||
|
|
||||||
const onChange = (flag: "flagA" | "flagB") => (index: number) => {
|
const onChange = (flag: "flagA" | "flagB") => (index: number) => {
|
||||||
if (flagMode === "country") {
|
if (flagMode === "country") {
|
||||||
dispatch(setPrototypeState({
|
dispatch(updateAngledFlagCountry({
|
||||||
angledFlagCountry: {
|
[flag]: countries[index],
|
||||||
flagA: flag === "flagA"
|
|
||||||
? countries[index]
|
|
||||||
: prototypeState?.angledFlagCountry?.flagA ?? DEFAULT_COUNTRY,
|
|
||||||
flagB: flag === "flagB"
|
|
||||||
? countries[index]
|
|
||||||
: prototypeState?.angledFlagCountry?.flagB ?? DEFAULT_COUNTRY,
|
|
||||||
},
|
|
||||||
}));
|
}));
|
||||||
} else if (flagMode === "team") {
|
} else if (flagMode === "team") {
|
||||||
dispatch(setPrototypeState({
|
dispatch(updateAngledFlagTeam({
|
||||||
angledFlagTeam: {
|
[flag]: teams[index],
|
||||||
flagA: flag === "flagA"
|
|
||||||
? teams[index]
|
|
||||||
: prototypeState?.angledFlagTeam?.flagA ?? DEFAULT_TEAM,
|
|
||||||
flagB: flag === "flagB"
|
|
||||||
? teams[index]
|
|
||||||
: prototypeState?.angledFlagTeam?.flagB ?? DEFAULT_TEAM,
|
|
||||||
},
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|||||||
+5
-10
@@ -1,8 +1,9 @@
|
|||||||
import { InlineCluster } from "@bedrock-layout/inline-cluster";
|
import { InlineCluster } from "@bedrock-layout/inline-cluster";
|
||||||
import { PadBox } from "@bedrock-layout/padbox";
|
import { PadBox } from "@bedrock-layout/padbox";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
|
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
|
||||||
import { setPrototypeState } from "../../../../features/workspace/workspaceSlice";
|
import { updateVenetianTransition } from "../../../../features/workspace/workspaceSlice";
|
||||||
import { VenetianTransitionWorkspaceMode } from "../../../../types/state";
|
import { VenetianTransitionWorkspaceMode } from "../../../../types/state";
|
||||||
|
|
||||||
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
|
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
|
||||||
@@ -18,20 +19,14 @@ export function VenetianBlindsPrototypeControls() {
|
|||||||
const { prototypeState } = useSelector(workspaceSelector);
|
const { prototypeState } = useSelector(workspaceSelector);
|
||||||
|
|
||||||
const onChange = (index: number) => {
|
const onChange = (index: number) => {
|
||||||
dispatch(setPrototypeState({
|
dispatch(updateVenetianTransition({
|
||||||
venetianTransition: {
|
|
||||||
mode: modes[index],
|
mode: modes[index],
|
||||||
showBG: prototypeState?.venetianTransition?.showBG ?? false,
|
|
||||||
},
|
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const onToggle = (value: boolean) => {
|
const onToggle = (value: boolean) => {
|
||||||
dispatch(setPrototypeState({
|
dispatch(updateVenetianTransition({
|
||||||
venetianTransition: {
|
|
||||||
mode: prototypeState?.venetianTransition?.mode ?? "positionFlag",
|
|
||||||
showBG: value,
|
showBG: value,
|
||||||
},
|
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,7 +39,7 @@ export function VenetianBlindsPrototypeControls() {
|
|||||||
slotWidth="200px"
|
slotWidth="200px"
|
||||||
/>
|
/>
|
||||||
<Toggle
|
<Toggle
|
||||||
toggled={prototypeState?.venetianTransition?.showBG ?? false}
|
toggled={prototypeState?.venetianTransition?.showBG ?? true}
|
||||||
onToggle={onToggle}
|
onToggle={onToggle}
|
||||||
label="Show BG"
|
label="Show BG"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const initialState: RootState["workspace"] = {
|
|||||||
overlayIds: [],
|
overlayIds: [],
|
||||||
previewWindowDimensions: { width: 0, height: 0 },
|
previewWindowDimensions: { width: 0, height: 0 },
|
||||||
},
|
},
|
||||||
prototypeState: null,
|
prototypeState: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpdateWorkspaceAction = {
|
export type UpdateWorkspaceAction = {
|
||||||
@@ -31,8 +31,54 @@ export const workspaceSlice = createSlice({
|
|||||||
state.workspaceId = action.payload.workspaceId;
|
state.workspaceId = action.payload.workspaceId;
|
||||||
state.workspaceProperties = action.payload.workspaceProperties;
|
state.workspaceProperties = action.payload.workspaceProperties;
|
||||||
},
|
},
|
||||||
setPrototypeState: (state, action: PayloadAction<PrototypeState>) => {
|
|
||||||
state.prototypeState = action.payload;
|
// Prototype States
|
||||||
|
updateAngledFlagCountry: (
|
||||||
|
state,
|
||||||
|
action: PayloadAction<Partial<PrototypeState["angledFlagCountry"]>>,
|
||||||
|
) => {
|
||||||
|
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<Partial<PrototypeState["angledFlagTeam"]>>,
|
||||||
|
) => {
|
||||||
|
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<Partial<PrototypeState["venetianTransition"]>>,
|
||||||
|
) => {
|
||||||
|
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,
|
setWorkspaceId,
|
||||||
setAnimatedBG,
|
setAnimatedBG,
|
||||||
updateWorkspace,
|
updateWorkspace,
|
||||||
setPrototypeState,
|
updateAngledFlagCountry,
|
||||||
|
updateAngledFlagTeam,
|
||||||
|
updateVenetianTransition,
|
||||||
} = workspaceSlice.actions;
|
} = workspaceSlice.actions;
|
||||||
export default workspaceSlice.reducer;
|
export default workspaceSlice.reducer;
|
||||||
Vendored
+4
-1
@@ -1,4 +1,5 @@
|
|||||||
import { Milliseconds, Optional } from "./util";
|
import { Milliseconds, Optional } from "./util";
|
||||||
|
import { Corner } from "./style";
|
||||||
|
|
||||||
export interface RootState {
|
export interface RootState {
|
||||||
pageDimensions: PageDimensions;
|
pageDimensions: PageDimensions;
|
||||||
@@ -22,7 +23,7 @@ export interface Workspace {
|
|||||||
workspaceId: WorkspaceId;
|
workspaceId: WorkspaceId;
|
||||||
animatedBG: boolean;
|
animatedBG: boolean;
|
||||||
workspaceProperties: WorkspaceProperties;
|
workspaceProperties: WorkspaceProperties;
|
||||||
prototypeState: Optional<PrototypeState>;
|
prototypeState: PrototypeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WorkspaceId = string;
|
export type WorkspaceId = string;
|
||||||
@@ -43,6 +44,8 @@ export interface PrototypeState {
|
|||||||
venetianTransition?: {
|
venetianTransition?: {
|
||||||
mode: VenetianTransitionWorkspaceMode;
|
mode: VenetianTransitionWorkspaceMode;
|
||||||
showBG: boolean;
|
showBG: boolean;
|
||||||
|
timing: number,
|
||||||
|
startingCorner: Corner,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export type VenetianTransitionWorkspaceMode = "positionFlag" | "driverPortrait";
|
export type VenetianTransitionWorkspaceMode = "positionFlag" | "driverPortrait";
|
||||||
|
|||||||
Reference in new issue
Block a user