ISSUE-017 - Overlay state is streamlined.
Total change to workspaces. Now an object instead of a list. Utilizing workspace overlays list - prototype currently colors the mock item. Reset overlay on workspace change. Improved combined dragging/transition element behavior.
This commit is contained in:
1 parent
a6a5eb7751
commit
861d702a27
11 files changed
+163
-136
No files matched your search
@@ -22,6 +22,7 @@
|
|||||||
"@testing-library/user-event": "^13.2.1",
|
"@testing-library/user-event": "^13.2.1",
|
||||||
"@types/d3": "^7.1.0",
|
"@types/d3": "^7.1.0",
|
||||||
"@types/jest": "^27.0.1",
|
"@types/jest": "^27.0.1",
|
||||||
|
"@types/lodash": "^4.14.178",
|
||||||
"@types/node": "^16.7.13",
|
"@types/node": "^16.7.13",
|
||||||
"@types/react": "^17.0.20",
|
"@types/react": "^17.0.20",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
"@use-gesture/react": "^10.2.4",
|
"@use-gesture/react": "^10.2.4",
|
||||||
"d3": "^7.2.1",
|
"d3": "^7.2.1",
|
||||||
"history": "5",
|
"history": "5",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-redux": "^7.2.6",
|
"react-redux": "^7.2.6",
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ import { Toggle } from "../../Common/Inputs/Toggle";
|
|||||||
|
|
||||||
export function OverlayControl() {
|
export function OverlayControl() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { visible, currentOverlayItem } = useSelector(overlayToolSelector);
|
const { overlayIds, visible, currentOverlayItem } = useSelector(overlayToolSelector);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* For prototyping use only */
|
/* For prototyping use only */
|
||||||
const [overlayId, setOverlayId] = useState("foo_1.00000");
|
const [idNum, setIdNum] = useState(0);
|
||||||
|
|
||||||
const getRandomArbitrary = (min: number, max: number) =>
|
const getRandomArbitrary = (min: number, max: number) =>
|
||||||
Math.random() * (max - min) + min;
|
Math.random() * (max - min) + min;
|
||||||
@@ -32,10 +32,10 @@ export function OverlayControl() {
|
|||||||
y: Math.floor(getRandomArbitrary(-50, 650)),
|
y: Math.floor(getRandomArbitrary(-50, 650)),
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
const idRandomizer = () => {
|
const nextIdNum = () => {
|
||||||
const newId = `id_${getRandomArbitrary(1, 10)}`.slice(0, 10);
|
const nextIdNum = (idNum + 1) % overlayIds.length;
|
||||||
setOverlayId(newId);
|
setIdNum(nextIdNum);
|
||||||
dispatch(setCurrentOverlayId(newId));
|
dispatch(setCurrentOverlayId(overlayIds[nextIdNum]));
|
||||||
};
|
};
|
||||||
/* For prototyping use only */
|
/* For prototyping use only */
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ export function OverlayControl() {
|
|||||||
const onToggle = (value: boolean) => {
|
const onToggle = (value: boolean) => {
|
||||||
if (currentOverlayItem == null) {
|
if (currentOverlayItem == null) {
|
||||||
dispatch(initNewOverlayItem({
|
dispatch(initNewOverlayItem({
|
||||||
overlayId,
|
overlayId: overlayIds[idNum],
|
||||||
initialPosition: { x: 400, y: 300 },
|
initialPosition: { x: 0, y: 300 },
|
||||||
setVisible: true,
|
setVisible: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
@@ -70,9 +70,9 @@ export function OverlayControl() {
|
|||||||
</a>
|
</a>
|
||||||
<br />
|
<br />
|
||||||
<a
|
<a
|
||||||
onClick={idRandomizer}
|
onClick={nextIdNum}
|
||||||
>
|
>
|
||||||
Id: {overlayId}
|
Id #{idNum}: "{overlayIds[idNum]}"
|
||||||
</a>
|
</a>
|
||||||
{/* For prototyping use only */}
|
{/* For prototyping use only */}
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,21 @@ import { useDrag } from "@use-gesture/react";
|
|||||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||||
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
|
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
|
||||||
|
|
||||||
import { AnimatedOverlayItemContainer } from "./styles";
|
import { OverlayItemContainer } from "./styles";
|
||||||
|
|
||||||
export function OverlayDisplay() {
|
export function OverlayDisplay() {
|
||||||
const { currentOverlayItem, visible } = useSelector(overlayToolSelector);
|
const {
|
||||||
|
currentOverlayId,
|
||||||
|
currentOverlayItem,
|
||||||
|
visible,
|
||||||
|
} = useSelector(overlayToolSelector);
|
||||||
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const bindOverlayItem = useDrag((state) => {
|
|
||||||
|
const bindOverlayItem = useDrag(({ args, delta }) => {
|
||||||
dispatch(setPosition({
|
dispatch(setPosition({
|
||||||
x: state.args[0].xPos + state.delta[0],
|
x: args[0].xPos + delta[0],
|
||||||
y: state.args[0].yPos + state.delta[1],
|
y: args[0].yPos + delta[1],
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -28,31 +34,33 @@ export function OverlayDisplay() {
|
|||||||
leave: { top: 50, opacity: 0 },
|
leave: { top: 50, opacity: 0 },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (currentOverlayItem == null) {
|
// Cannot make an earlier return because all hooks must run or React gets mad.
|
||||||
return null; // Exit - There is no overlay item yet!
|
if (currentOverlayId == null || currentOverlayItem == null) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id, position } = currentOverlayItem;
|
const { position } = currentOverlayItem;
|
||||||
|
|
||||||
return (
|
return transition((style, visible) =>
|
||||||
transition((style, visible) =>
|
|
||||||
visible ? (
|
visible ? (
|
||||||
<animated.div style={{ ...style, position: "absolute" }}>
|
<animated.div
|
||||||
<AnimatedOverlayItemContainer
|
|
||||||
{...bindOverlayItem({ xPos, yPos })}
|
{...bindOverlayItem({ xPos, yPos })}
|
||||||
style={{
|
style={{
|
||||||
left: xPos,
|
left: xPos,
|
||||||
top: yPos,
|
top: yPos,
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
|
touchAction: "none",
|
||||||
|
zIndex: 1,
|
||||||
}}
|
}}
|
||||||
visible={visible}
|
|
||||||
>
|
>
|
||||||
{id}
|
<animated.div style={{ ...style, position: "absolute" }}>
|
||||||
|
<OverlayItemContainer visible={visible} tempColor={currentOverlayId}>
|
||||||
|
{currentOverlayId}
|
||||||
<br />
|
<br />
|
||||||
(x:{position.x}px, y:{position.y}px)
|
(x:{Math.floor(position.x)}px, y:{Math.floor(position.y)}px)
|
||||||
</AnimatedOverlayItemContainer>
|
</OverlayItemContainer>
|
||||||
|
</animated.div>
|
||||||
</animated.div>
|
</animated.div>
|
||||||
) : null,
|
) : null,
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,47 +1,21 @@
|
|||||||
import { animated } from "@react-spring/web";
|
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
import { OverlayPosition } from "../../../types/state";
|
|
||||||
|
|
||||||
export type OverlayItemContainerProps = {
|
export type OverlayItemContainerProps = {
|
||||||
position: OverlayPosition,
|
|
||||||
visible: boolean,
|
visible: boolean,
|
||||||
|
tempColor: string,
|
||||||
};
|
};
|
||||||
export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(({
|
export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(({
|
||||||
position: { x, y },
|
|
||||||
visible,
|
visible,
|
||||||
}) => ({
|
}) => ({
|
||||||
style: {
|
style: {
|
||||||
top: y,
|
|
||||||
left: x,
|
|
||||||
display: visible ? undefined : "none",
|
display: visible ? undefined : "none",
|
||||||
},
|
},
|
||||||
}))<OverlayItemContainerProps>`
|
}))<OverlayItemContainerProps>`
|
||||||
/* Temporary. Overlay will be transparent and based on an image. */
|
/* Temporary. Overlay will be transparent and based on an image. */
|
||||||
width: 150px;
|
width: 150px;
|
||||||
height: 150px;
|
height: 150px;
|
||||||
background-color: white;
|
background-color: ${({ tempColor }) => tempColor};
|
||||||
box-shadow: 0px 7px 11px 1px black;
|
box-shadow: 0px 7px 11px 1px black;
|
||||||
`;
|
`;
|
||||||
OverlayItemContainer.displayName = "OverlayItemContainer";
|
OverlayItemContainer.displayName = "OverlayItemContainer";
|
||||||
|
|
||||||
type AnimatedOverlayItemContainerProps = {
|
|
||||||
visible: boolean,
|
|
||||||
}
|
|
||||||
export const AnimatedOverlayItemContainer = styled(animated.div).attrs<AnimatedOverlayItemContainerProps>(({
|
|
||||||
visible,
|
|
||||||
}) => ({
|
|
||||||
style: {
|
|
||||||
display: visible ? undefined : "none",
|
|
||||||
},
|
|
||||||
}))<AnimatedOverlayItemContainerProps>`
|
|
||||||
position: absolute;
|
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
/* Temporary. Overlay will be transparent and based on an image. */
|
|
||||||
width: 150px;
|
|
||||||
height: 150px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 0px 7px 11px 1px black;
|
|
||||||
`;
|
|
||||||
|
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { Center } from "@bedrock-layout/center";
|
import { Center } from "@bedrock-layout/center";
|
||||||
import { Stack } from "@bedrock-layout/stack";
|
import { Stack } from "@bedrock-layout/stack";
|
||||||
|
|
||||||
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
||||||
|
import { setWorkspaceId } from "../../../features/workspace/workspaceSlice";
|
||||||
|
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||||
|
import { newWorkspace } from "../../../features/overlayTool/overlayToolSlice";
|
||||||
|
|
||||||
import { PreviewWindow, H2, ControlsContainer } from "./styles";
|
import { PreviewWindow, H2, ControlsContainer } from "./styles";
|
||||||
import { WorkspaceControls } from "./WorkspaceControls";
|
import { WorkspaceControls } from "./WorkspaceControls";
|
||||||
@@ -15,6 +19,24 @@ import { workspaceObject } from "../workspaces";
|
|||||||
export const Workspace = () => {
|
export const Workspace = () => {
|
||||||
const { workspaceId } = useParams();
|
const { workspaceId } = useParams();
|
||||||
const { animatedBG } = useSelector(workspaceSelector);
|
const { animatedBG } = useSelector(workspaceSelector);
|
||||||
|
const { currentWorkspaceId: overlayWorkspaceId } = useSelector(overlayToolSelector);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (workspaceId == null) return;
|
||||||
|
|
||||||
|
// Update workspace store for ID.
|
||||||
|
dispatch(setWorkspaceId(workspaceId));
|
||||||
|
|
||||||
|
// Switching Workspace means we need to init a newWorkspace for Overlay tool.
|
||||||
|
if (overlayWorkspaceId !== workspaceId) {
|
||||||
|
dispatch(newWorkspace({
|
||||||
|
overlayIds: workspaceObject[workspaceId].overlayIds,
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [workspaceId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
gutter="lg"
|
gutter="lg"
|
||||||
@@ -22,7 +44,7 @@ export const Workspace = () => {
|
|||||||
maxWidth="80%"
|
maxWidth="80%"
|
||||||
centerChildren
|
centerChildren
|
||||||
>
|
>
|
||||||
<H2>{workspaceId ? workspaceObject[workspaceId] : "Unknown"}</H2>
|
<H2>{workspaceId ? workspaceObject[workspaceId].name : "Unknown"}</H2>
|
||||||
<PreviewWindow height={600} width={800} animatedBG={animatedBG}>
|
<PreviewWindow height={600} width={800} animatedBG={animatedBG}>
|
||||||
<MockupBlock
|
<MockupBlock
|
||||||
color="#415bad"
|
color="#415bad"
|
||||||
|
|||||||
@@ -1,21 +1,31 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
import { NavLink } from "react-router-dom";
|
||||||
|
|
||||||
import { WorkspaceListBox } from "./styles";
|
import { WorkspaceListBox } from "./styles";
|
||||||
import { Stack } from "@bedrock-layout/stack";
|
import { Stack } from "@bedrock-layout/stack";
|
||||||
import { NavLink } from "react-router-dom";
|
|
||||||
import { MenuItem } from "../../Common/MenuItem.styled";
|
import { MenuItem } from "../../Common/MenuItem.styled";
|
||||||
import { workspaceList } from "../workspaces";
|
|
||||||
|
import { workspaceObject } from "../workspaces";
|
||||||
|
|
||||||
type WorkspaceListProps = {
|
type WorkspaceListProps = {
|
||||||
headerOffset?: number,
|
headerOffset?: number,
|
||||||
};
|
};
|
||||||
export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => (
|
export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
|
||||||
|
const workspaceList = _.keys(workspaceObject);
|
||||||
|
return (
|
||||||
<WorkspaceListBox headerOffset={headerOffset}>
|
<WorkspaceListBox headerOffset={headerOffset}>
|
||||||
<Stack as="ul" gutter="md">
|
<Stack as="ul" gutter="md">
|
||||||
{workspaceList.map((workspace, i) => (
|
{workspaceList.map((id, i) => (
|
||||||
<WorkspaceListNavLink key={i} to={workspace.id} label={workspace.name} />
|
<WorkspaceListNavLink
|
||||||
|
key={id}
|
||||||
|
to={id}
|
||||||
|
label={workspaceObject[id].name}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</WorkspaceListBox>
|
</WorkspaceListBox>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
type WorkspaceListNavLinkProps = {
|
type WorkspaceListNavLinkProps = {
|
||||||
to: string,
|
to: string,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { LayoutGrid, LayoutGridItem } from "../Common/LayoutGrid.styled";
|
|||||||
const WORKSPACE_LIST_WIDTH = 180;
|
const WORKSPACE_LIST_WIDTH = 180;
|
||||||
|
|
||||||
export default function Workspaces() {
|
export default function Workspaces() {
|
||||||
const { height } = useSelector(mainMenuDimensionsSelector);
|
const { height: mainMenuHeight } = useSelector(mainMenuDimensionsSelector);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [workspaceRef, {
|
const [workspaceRef, {
|
||||||
height: workspaceHeight,
|
height: workspaceHeight,
|
||||||
@@ -31,14 +31,14 @@ export default function Workspaces() {
|
|||||||
return (
|
return (
|
||||||
<LayoutGrid columns={[`${WORKSPACE_LIST_WIDTH}px`, 1]} rows={1}>
|
<LayoutGrid columns={[`${WORKSPACE_LIST_WIDTH}px`, 1]} rows={1}>
|
||||||
<LayoutGridItem column={1} row={1}>
|
<LayoutGridItem column={1} row={1}>
|
||||||
<WorkspaceList headerOffset={height} />
|
<WorkspaceList headerOffset={mainMenuHeight} />
|
||||||
</LayoutGridItem>
|
</LayoutGridItem>
|
||||||
<LayoutGridItem column={2} row={1}>
|
<LayoutGridItem column={2} row={1}>
|
||||||
<FullScreenContainer
|
<FullScreenContainer
|
||||||
ref={workspaceRef}
|
ref={workspaceRef}
|
||||||
minHeight={700}
|
minHeight={700}
|
||||||
minWidth={900}
|
minWidth={900}
|
||||||
heightCutoff={height}
|
heightCutoff={mainMenuHeight}
|
||||||
widthCutoff={WORKSPACE_LIST_WIDTH}
|
widthCutoff={WORKSPACE_LIST_WIDTH}
|
||||||
>
|
>
|
||||||
<Outlet />
|
<Outlet />
|
||||||
|
|||||||
@@ -1,56 +1,57 @@
|
|||||||
export const workspaceList = [
|
import { OverlayIds } from "../../types/state";
|
||||||
{
|
|
||||||
|
export type WorkspaceObject = {
|
||||||
|
[id: string]: {
|
||||||
|
name: string,
|
||||||
|
overlayIds: OverlayIds,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export const workspaceObject: WorkspaceObject = {
|
||||||
|
workspace1: {
|
||||||
name: "Workspace 1",
|
name: "Workspace 1",
|
||||||
id: "workspace1",
|
overlayIds: ["red", "blue", "white"],
|
||||||
},
|
},
|
||||||
{
|
workspace2: {
|
||||||
name: "Workspace 2",
|
name: "Workspace 2",
|
||||||
id: "workspace2",
|
overlayIds: ["green"],
|
||||||
},
|
},
|
||||||
{
|
workspace3: {
|
||||||
name: "Workspace 3",
|
name: "Workspace 3",
|
||||||
id: "workspace3",
|
overlayIds: ["green"],
|
||||||
},
|
},
|
||||||
{
|
workspace4: {
|
||||||
name: "Workspace 4 has a longer name than the rest",
|
name: "Workspace 4 has a longer name than the rest",
|
||||||
id: "workspace4",
|
overlayIds: ["green"],
|
||||||
},
|
},
|
||||||
{ name: "blah", id: "blah0" },
|
blah0: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah1" },
|
blah1: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah2" },
|
blah2: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah3" },
|
blah3: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah4" },
|
blah4: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah5" },
|
blah5: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah6" },
|
blah6: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah7" },
|
blah7: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah8" },
|
blah8: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah9" },
|
blah9: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah10" },
|
blah10: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah11" },
|
blah11: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah12" },
|
blah12: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah13" },
|
blah13: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah14" },
|
blah14: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah15" },
|
blah15: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah16" },
|
blah16: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah17" },
|
blah17: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah18" },
|
blah18: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah19" },
|
blah19: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah20" },
|
blah20: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah21" },
|
blah21: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah22" },
|
blah22: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah23" },
|
blah23: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah24" },
|
blah24: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah25" },
|
blah25: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah26" },
|
blah26: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah27" },
|
blah27: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah28" },
|
blah28: { name: "blah", overlayIds: ["green"] },
|
||||||
{ name: "blah", id: "blah29" },
|
blah29: { name: "blah", overlayIds: ["green"] },
|
||||||
];
|
};
|
||||||
|
|
||||||
export const workspaceObject = ((list: typeof workspaceList) => {
|
|
||||||
const obj: {[key: string]: string} = {};
|
|
||||||
list.forEach(item => {
|
|
||||||
obj[item.id] = item.name;
|
|
||||||
});
|
|
||||||
return obj;
|
|
||||||
})(workspaceList);
|
|
||||||
@@ -2,27 +2,20 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
RootState,
|
RootState,
|
||||||
|
WorkspaceId,
|
||||||
OverlayPosition,
|
OverlayPosition,
|
||||||
OverlayId,
|
OverlayId,
|
||||||
|
OverlayIds,
|
||||||
} from "../../types/state";
|
} from "../../types/state";
|
||||||
|
|
||||||
const initialState: RootState["overlayTool"] = {
|
const initialState: RootState["overlayTool"] = {
|
||||||
|
currentWorkspaceId: "",
|
||||||
overlayIds: [],
|
overlayIds: [],
|
||||||
currentOverlayId: null,
|
currentOverlayId: null,
|
||||||
currentOverlayItem: null,
|
currentOverlayItem: null,
|
||||||
visible: false,
|
visible: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeNewOverlayItem = (
|
|
||||||
overlayId: OverlayId,
|
|
||||||
initialPosition: OverlayPosition,
|
|
||||||
) => ({
|
|
||||||
id: overlayId,
|
|
||||||
position: initialPosition,
|
|
||||||
opacity: 1,
|
|
||||||
scale: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
type InitNewOverlayItemAction = {
|
type InitNewOverlayItemAction = {
|
||||||
overlayId: OverlayId,
|
overlayId: OverlayId,
|
||||||
@@ -30,16 +23,21 @@ type InitNewOverlayItemAction = {
|
|||||||
setVisible: boolean,
|
setVisible: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type NewWorkspaceAction = {
|
||||||
|
overlayIds: OverlayIds,
|
||||||
|
workspaceId: WorkspaceId,
|
||||||
|
}
|
||||||
|
|
||||||
export const overlayToolSlice = createSlice({
|
export const overlayToolSlice = createSlice({
|
||||||
name: "overlayTool",
|
name: "overlayTool",
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
initNewOverlayItem: (state, action: PayloadAction<InitNewOverlayItemAction>) => {
|
initNewOverlayItem: (state, action: PayloadAction<InitNewOverlayItemAction>) => {
|
||||||
if (state.currentOverlayItem == null) {
|
if (state.currentOverlayItem == null) {
|
||||||
state.currentOverlayItem = makeNewOverlayItem(
|
state.currentOverlayItem = {
|
||||||
action.payload.overlayId,
|
position: action.payload.initialPosition,
|
||||||
action.payload.initialPosition,
|
opacity: 1,
|
||||||
);
|
};
|
||||||
state.currentOverlayId = action.payload.overlayId;
|
state.currentOverlayId = action.payload.overlayId;
|
||||||
state.visible = action.payload.setVisible;
|
state.visible = action.payload.setVisible;
|
||||||
}
|
}
|
||||||
@@ -47,16 +45,12 @@ export const overlayToolSlice = createSlice({
|
|||||||
setVisibility: (state, action: PayloadAction<boolean>) => {
|
setVisibility: (state, action: PayloadAction<boolean>) => {
|
||||||
state.visible = action.payload;
|
state.visible = action.payload;
|
||||||
},
|
},
|
||||||
setOverlayIds: (state, action: PayloadAction<Array<OverlayId>>) => {
|
|
||||||
state.overlayIds = action.payload;
|
|
||||||
},
|
|
||||||
setCurrentOverlayId: (state, action: PayloadAction<OverlayId>) => {
|
setCurrentOverlayId: (state, action: PayloadAction<OverlayId>) => {
|
||||||
if (
|
if (
|
||||||
action.payload !== state.currentOverlayId &&
|
action.payload !== state.currentOverlayId &&
|
||||||
state.currentOverlayItem != null
|
state.currentOverlayItem != null
|
||||||
) {
|
) {
|
||||||
state.currentOverlayId = action.payload;
|
state.currentOverlayId = action.payload;
|
||||||
state.currentOverlayItem.id = action.payload;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setPosition: (state, action: PayloadAction<OverlayPosition>) => {
|
setPosition: (state, action: PayloadAction<OverlayPosition>) => {
|
||||||
@@ -64,14 +58,21 @@ export const overlayToolSlice = createSlice({
|
|||||||
state.currentOverlayItem.position = action.payload;
|
state.currentOverlayItem.position = action.payload;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
newWorkspace: (state, action: PayloadAction<NewWorkspaceAction>) => {
|
||||||
|
state.currentOverlayId = null;
|
||||||
|
state.currentOverlayItem = null;
|
||||||
|
state.visible = false;
|
||||||
|
state.currentWorkspaceId = action.payload.workspaceId;
|
||||||
|
state.overlayIds = action.payload.overlayIds;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
initNewOverlayItem,
|
initNewOverlayItem,
|
||||||
setVisibility,
|
setVisibility,
|
||||||
setOverlayIds,
|
|
||||||
setCurrentOverlayId,
|
setCurrentOverlayId,
|
||||||
setPosition,
|
setPosition,
|
||||||
|
newWorkspace,
|
||||||
} = overlayToolSlice.actions;
|
} = overlayToolSlice.actions;
|
||||||
export default overlayToolSlice.reducer;
|
export default overlayToolSlice.reducer;
|
||||||
Vendored
+3
-4
@@ -22,17 +22,16 @@ export type WorkspaceId = string;
|
|||||||
|
|
||||||
// Overlay Tool
|
// Overlay Tool
|
||||||
export type OverlayTool = {
|
export type OverlayTool = {
|
||||||
// workspaceId: WorkspaceId,
|
currentWorkspaceId: WorkspaceId,
|
||||||
overlayIds: Array<OverlayId>,
|
overlayIds: OverlayIds,
|
||||||
currentOverlayId: OverlayId | null,
|
currentOverlayId: OverlayId | null,
|
||||||
currentOverlayItem: OverlayItem | null,
|
currentOverlayItem: OverlayItem | null,
|
||||||
visible: boolean,
|
visible: boolean,
|
||||||
};
|
};
|
||||||
export type OverlayId = string;
|
export type OverlayId = string;
|
||||||
|
export type OverlayIds = Array<OverlayId>;
|
||||||
export type OverlayPosition = { x: number, y: number };
|
export type OverlayPosition = { x: number, y: number };
|
||||||
export type OverlayItem = {
|
export type OverlayItem = {
|
||||||
id: OverlayId,
|
|
||||||
position: OverlayPosition,
|
position: OverlayPosition,
|
||||||
opacity: number,
|
opacity: number,
|
||||||
scale: number,
|
|
||||||
};
|
};
|
||||||
@@ -2103,6 +2103,11 @@
|
|||||||
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz"
|
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz"
|
||||||
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
|
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
|
||||||
|
|
||||||
|
"@types/lodash@^4.14.178":
|
||||||
|
version "4.14.178"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
|
||||||
|
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==
|
||||||
|
|
||||||
"@types/node@*":
|
"@types/node@*":
|
||||||
version "17.0.0"
|
version "17.0.0"
|
||||||
resolved "https://registry.npmjs.org/@types/node/-/node-17.0.0.tgz"
|
resolved "https://registry.npmjs.org/@types/node/-/node-17.0.0.tgz"
|
||||||
@@ -6334,11 +6339,16 @@ lodash.uniq@^4.5.0:
|
|||||||
resolved "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz"
|
resolved "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz"
|
||||||
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
|
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
|
||||||
|
|
||||||
lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.7.0:
|
lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.20, lodash@^4.7.0:
|
||||||
version "4.17.21"
|
version "4.17.21"
|
||||||
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
|
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
|
||||||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||||
|
|
||||||
|
lodash@^4.17.21:
|
||||||
|
version "4.17.21"
|
||||||
|
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||||
|
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||||
|
|
||||||
loose-envify@^1.1.0, loose-envify@^1.4.0:
|
loose-envify@^1.1.0, loose-envify@^1.4.0:
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
resolved "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz"
|
resolved "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz"
|
||||||
|
|||||||
Reference in new issue
Block a user