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
+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}: "{overlayIds[idNum]}"
|
||||
</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;
|
||||
`;
|
||||
|
||||
Reference in new issue
Block a user