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.
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import { useState } from "react";
|
|
import { useSelector, useDispatch } from "react-redux";
|
|
import { PadBox } from "@bedrock-layout/padbox";
|
|
|
|
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
|
import {
|
|
initNewOverlayItem,
|
|
setCurrentOverlayId,
|
|
setPosition,
|
|
setVisibility,
|
|
} from "../../../features/overlayTool/overlayToolSlice";
|
|
|
|
import { Toggle } from "../../Common/Inputs/Toggle";
|
|
|
|
|
|
export function OverlayControl() {
|
|
const dispatch = useDispatch();
|
|
const { overlayIds, visible, currentOverlayItem } = useSelector(overlayToolSelector);
|
|
|
|
|
|
|
|
|
|
/* For prototyping use only */
|
|
const [idNum, setIdNum] = useState(0);
|
|
|
|
const getRandomArbitrary = (min: number, max: number) =>
|
|
Math.random() * (max - min) + min;
|
|
|
|
const posRandomizer = () => {
|
|
dispatch(setPosition({
|
|
x: Math.floor(getRandomArbitrary(-50, 850)),
|
|
y: Math.floor(getRandomArbitrary(-50, 650)),
|
|
}));
|
|
};
|
|
const nextIdNum = () => {
|
|
const nextIdNum = (idNum + 1) % overlayIds.length;
|
|
setIdNum(nextIdNum);
|
|
dispatch(setCurrentOverlayId(overlayIds[nextIdNum]));
|
|
};
|
|
/* For prototyping use only */
|
|
|
|
|
|
|
|
const onToggle = (value: boolean) => {
|
|
if (currentOverlayItem == null) {
|
|
dispatch(initNewOverlayItem({
|
|
overlayId: overlayIds[idNum],
|
|
initialPosition: { x: 0, y: 300 },
|
|
setVisible: true,
|
|
}));
|
|
} else {
|
|
dispatch(setVisibility(value));
|
|
}
|
|
};
|
|
|
|
return (
|
|
<PadBox padding="sm">
|
|
<Toggle
|
|
label="Show Overlay"
|
|
toggled={visible}
|
|
onToggle={onToggle}
|
|
/>
|
|
|
|
{/* For prototyping use only */}
|
|
<br />
|
|
<a
|
|
onClick={posRandomizer}
|
|
>
|
|
Random Location
|
|
</a>
|
|
<br />
|
|
<a
|
|
onClick={nextIdNum}
|
|
>
|
|
Id #{idNum}: "{overlayIds[idNum]}"
|
|
</a>
|
|
{/* For prototyping use only */}
|
|
|
|
</PadBox>
|
|
);
|
|
}
|