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:
Kyle Geib committed 2022-01-13 14:16:09 -05:00
1 parent a6a5eb7751
commit 861d702a27
11 files changed
+177 -150

No files matched your search

@@ -15,13 +15,13 @@ import { Toggle } from "../../Common/Inputs/Toggle";
export function OverlayControl() {
const dispatch = useDispatch();
const { visible, currentOverlayItem } = useSelector(overlayToolSelector);
const { overlayIds, visible, currentOverlayItem } = useSelector(overlayToolSelector);
/* For prototyping use only */
const [overlayId, setOverlayId] = useState("foo_1.00000");
const [idNum, setIdNum] = useState(0);
const getRandomArbitrary = (min: number, max: number) =>
Math.random() * (max - min) + min;
@@ -32,10 +32,10 @@ export function OverlayControl() {
y: Math.floor(getRandomArbitrary(-50, 650)),
}));
};
const idRandomizer = () => {
const newId = `id_${getRandomArbitrary(1, 10)}`.slice(0, 10);
setOverlayId(newId);
dispatch(setCurrentOverlayId(newId));
const nextIdNum = () => {
const nextIdNum = (idNum + 1) % overlayIds.length;
setIdNum(nextIdNum);
dispatch(setCurrentOverlayId(overlayIds[nextIdNum]));
};
/* For prototyping use only */
@@ -44,8 +44,8 @@ export function OverlayControl() {
const onToggle = (value: boolean) => {
if (currentOverlayItem == null) {
dispatch(initNewOverlayItem({
overlayId,
initialPosition: { x: 400, y: 300 },
overlayId: overlayIds[idNum],
initialPosition: { x: 0, y: 300 },
setVisible: true,
}));
} else {
@@ -70,9 +70,9 @@ export function OverlayControl() {
</a>
<br />
<a
onClick={idRandomizer}
onClick={nextIdNum}
>
Id: {overlayId}
Id #{idNum}: &quot;{overlayIds[idNum]}&quot;
</a>
{/* For prototyping use only */}
@@ -5,15 +5,21 @@ import { useDrag } from "@use-gesture/react";
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
import { AnimatedOverlayItemContainer } from "./styles";
import { OverlayItemContainer } from "./styles";
export function OverlayDisplay() {
const { currentOverlayItem, visible } = useSelector(overlayToolSelector);
const {
currentOverlayId,
currentOverlayItem,
visible,
} = useSelector(overlayToolSelector);
const dispatch = useDispatch();
const bindOverlayItem = useDrag((state) => {
const bindOverlayItem = useDrag(({ args, delta }) => {
dispatch(setPosition({
x: state.args[0].xPos + state.delta[0],
y: state.args[0].yPos + state.delta[1],
x: args[0].xPos + delta[0],
y: args[0].yPos + delta[1],
}));
});
@@ -28,31 +34,33 @@ export function OverlayDisplay() {
leave: { top: 50, opacity: 0 },
});
if (currentOverlayItem == null) {
return null; // Exit - There is no overlay item yet!
// Cannot make an earlier return because all hooks must run or React gets mad.
if (currentOverlayId == null || currentOverlayItem == null) {
return null;
}
const { id, position } = currentOverlayItem;
const { position } = currentOverlayItem;
return (
transition((style, visible) =>
visible ? (
return transition((style, visible) =>
visible ? (
<animated.div
{...bindOverlayItem({ xPos, yPos })}
style={{
left: xPos,
top: yPos,
position: "absolute",
touchAction: "none",
zIndex: 1,
}}
>
<animated.div style={{ ...style, position: "absolute" }}>
<AnimatedOverlayItemContainer
{...bindOverlayItem({ xPos, yPos })}
style={{
left: xPos,
top: yPos,
position: "absolute",
}}
visible={visible}
>
{id}
<OverlayItemContainer visible={visible} tempColor={currentOverlayId}>
{currentOverlayId}
<br />
(x:{position.x}px, y:{position.y}px)
</AnimatedOverlayItemContainer>
(x:{Math.floor(position.x)}px, y:{Math.floor(position.y)}px)
</OverlayItemContainer>
</animated.div>
) : null,
)
</animated.div>
) : null,
);
}
@@ -1,47 +1,21 @@
import { animated } from "@react-spring/web";
import styled from "styled-components";
import { OverlayPosition } from "../../../types/state";
export type OverlayItemContainerProps = {
position: OverlayPosition,
visible: boolean,
tempColor: string,
};
export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(({
position: { x, y },
visible,
}) => ({
style: {
top: y,
left: x,
display: visible ? undefined : "none",
},
}))<OverlayItemContainerProps>`
/* Temporary. Overlay will be transparent and based on an image. */
width: 150px;
height: 150px;
background-color: white;
background-color: ${({ tempColor }) => tempColor};
box-shadow: 0px 7px 11px 1px black;
`;
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 { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { Center } from "@bedrock-layout/center";
import { Stack } from "@bedrock-layout/stack";
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 { WorkspaceControls } from "./WorkspaceControls";
@@ -15,6 +19,24 @@ import { workspaceObject } from "../workspaces";
export const Workspace = () => {
const { workspaceId } = useParams();
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 (
<Stack
gutter="lg"
@@ -22,7 +44,7 @@ export const Workspace = () => {
maxWidth="80%"
centerChildren
>
<H2>{workspaceId ? workspaceObject[workspaceId] : "Unknown"}</H2>
<H2>{workspaceId ? workspaceObject[workspaceId].name : "Unknown"}</H2>
<PreviewWindow height={600} width={800} animatedBG={animatedBG}>
<MockupBlock
color="#415bad"
@@ -1,21 +1,31 @@
import _ from "lodash";
import { NavLink } from "react-router-dom";
import { WorkspaceListBox } from "./styles";
import { Stack } from "@bedrock-layout/stack";
import { NavLink } from "react-router-dom";
import { MenuItem } from "../../Common/MenuItem.styled";
import { workspaceList } from "../workspaces";
import { workspaceObject } from "../workspaces";
type WorkspaceListProps = {
headerOffset?: number,
};
export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => (
<WorkspaceListBox headerOffset={headerOffset}>
<Stack as="ul" gutter="md">
{workspaceList.map((workspace, i) => (
<WorkspaceListNavLink key={i} to={workspace.id} label={workspace.name} />
))}
</Stack>
</WorkspaceListBox>
);
export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
const workspaceList = _.keys(workspaceObject);
return (
<WorkspaceListBox headerOffset={headerOffset}>
<Stack as="ul" gutter="md">
{workspaceList.map((id, i) => (
<WorkspaceListNavLink
key={id}
to={id}
label={workspaceObject[id].name}
/>
))}
</Stack>
</WorkspaceListBox>
);
};
type WorkspaceListNavLinkProps = {
to: string,
@@ -13,7 +13,7 @@ import { LayoutGrid, LayoutGridItem } from "../Common/LayoutGrid.styled";
const WORKSPACE_LIST_WIDTH = 180;
export default function Workspaces() {
const { height } = useSelector(mainMenuDimensionsSelector);
const { height: mainMenuHeight } = useSelector(mainMenuDimensionsSelector);
const dispatch = useDispatch();
const [workspaceRef, {
height: workspaceHeight,
@@ -31,14 +31,14 @@ export default function Workspaces() {
return (
<LayoutGrid columns={[`${WORKSPACE_LIST_WIDTH}px`, 1]} rows={1}>
<LayoutGridItem column={1} row={1}>
<WorkspaceList headerOffset={height} />
<WorkspaceList headerOffset={mainMenuHeight} />
</LayoutGridItem>
<LayoutGridItem column={2} row={1}>
<FullScreenContainer
ref={workspaceRef}
minHeight={700}
minWidth={900}
heightCutoff={height}
heightCutoff={mainMenuHeight}
widthCutoff={WORKSPACE_LIST_WIDTH}
>
<Outlet />
+48 -47
View File
@@ -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",
id: "workspace1",
overlayIds: ["red", "blue", "white"],
},
{
workspace2: {
name: "Workspace 2",
id: "workspace2",
overlayIds: ["green"],
},
{
workspace3: {
name: "Workspace 3",
id: "workspace3",
overlayIds: ["green"],
},
{
workspace4: {
name: "Workspace 4 has a longer name than the rest",
id: "workspace4",
overlayIds: ["green"],
},
{ name: "blah", id: "blah0" },
{ name: "blah", id: "blah1" },
{ name: "blah", id: "blah2" },
{ name: "blah", id: "blah3" },
{ name: "blah", id: "blah4" },
{ name: "blah", id: "blah5" },
{ name: "blah", id: "blah6" },
{ name: "blah", id: "blah7" },
{ name: "blah", id: "blah8" },
{ name: "blah", id: "blah9" },
{ name: "blah", id: "blah10" },
{ name: "blah", id: "blah11" },
{ name: "blah", id: "blah12" },
{ name: "blah", id: "blah13" },
{ name: "blah", id: "blah14" },
{ name: "blah", id: "blah15" },
{ name: "blah", id: "blah16" },
{ name: "blah", id: "blah17" },
{ name: "blah", id: "blah18" },
{ name: "blah", id: "blah19" },
{ name: "blah", id: "blah20" },
{ name: "blah", id: "blah21" },
{ name: "blah", id: "blah22" },
{ name: "blah", id: "blah23" },
{ name: "blah", id: "blah24" },
{ name: "blah", id: "blah25" },
{ name: "blah", id: "blah26" },
{ name: "blah", id: "blah27" },
{ name: "blah", id: "blah28" },
{ name: "blah", id: "blah29" },
];
blah0: { name: "blah", overlayIds: ["green"] },
blah1: { name: "blah", overlayIds: ["green"] },
blah2: { name: "blah", overlayIds: ["green"] },
blah3: { name: "blah", overlayIds: ["green"] },
blah4: { name: "blah", overlayIds: ["green"] },
blah5: { name: "blah", overlayIds: ["green"] },
blah6: { name: "blah", overlayIds: ["green"] },
blah7: { name: "blah", overlayIds: ["green"] },
blah8: { name: "blah", overlayIds: ["green"] },
blah9: { name: "blah", overlayIds: ["green"] },
blah10: { name: "blah", overlayIds: ["green"] },
blah11: { name: "blah", overlayIds: ["green"] },
blah12: { name: "blah", overlayIds: ["green"] },
blah13: { name: "blah", overlayIds: ["green"] },
blah14: { name: "blah", overlayIds: ["green"] },
blah15: { name: "blah", overlayIds: ["green"] },
blah16: { name: "blah", overlayIds: ["green"] },
blah17: { name: "blah", overlayIds: ["green"] },
blah18: { name: "blah", overlayIds: ["green"] },
blah19: { name: "blah", overlayIds: ["green"] },
blah20: { name: "blah", overlayIds: ["green"] },
blah21: { name: "blah", overlayIds: ["green"] },
blah22: { name: "blah", overlayIds: ["green"] },
blah23: { name: "blah", overlayIds: ["green"] },
blah24: { name: "blah", overlayIds: ["green"] },
blah25: { name: "blah", overlayIds: ["green"] },
blah26: { name: "blah", overlayIds: ["green"] },
blah27: { name: "blah", overlayIds: ["green"] },
blah28: { name: "blah", overlayIds: ["green"] },
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);