ISSUE-017 - Improvements to a number of things.
* Moved FullScreenContainer in WorkspacesRoute to make scrolling much better. Seriously, 100% works better. * Simplified dimensions state actions to a shared one. * Abandoned the noisy and useless "AnimatedBG" type. * Added workspace dimensions state (I'll need this later to prevent off-screen dragging). * Placed OverlayDisplay component in PreviewWindow, where it makes more sense. I'll still allow it to roam around outside of it, though. * Renamed "menu" dimensions to "mainMenu". * Improved initNewOverlayItem action to support setting visible. * Correct handling of showing the OverlayItemContainer. * Simplified the initial position of a new OverlayItem to a simple initial value instead of setting it in the middle of provided dimensions. * Made PreviewWindow `position: relative` to allow absolute positioning of OverlayItem from it. * Added importHelpers to tsconfig because VSCode was complaining about it.
This commit is contained in:
1 parent
506491eed9
commit
61b60b9819
16 files changed
+107
-70
No files matched your search
+20
-9
@@ -2,8 +2,7 @@ import { Outlet } from "react-router-dom";
|
||||
|
||||
import { useDimensions } from "./utils/hooks";
|
||||
import {
|
||||
setMenuDimensions,
|
||||
setAppDimensions,
|
||||
setDimensions,
|
||||
} from "./features/pageDimensions/pageDimensionsSlice";
|
||||
|
||||
import { MainMenu } from "./components/Menu";
|
||||
@@ -12,18 +11,30 @@ import { useEffect } from "react";
|
||||
|
||||
function App() {
|
||||
const dispatch = useDispatch();
|
||||
const [appRef, { height: appHeight, width: appWidth }] = useDimensions<HTMLDivElement>();
|
||||
const [mainMenuRef, { height: mainMenuHeight }] = useDimensions<HTMLDivElement>();
|
||||
const [appRef, {
|
||||
height: appHeight,
|
||||
width: appWidth,
|
||||
}] = useDimensions<HTMLDivElement>();
|
||||
const [mainMenuRef, {
|
||||
height: mainMenuHeight,
|
||||
width: mainMenuWidth,
|
||||
}] = useDimensions<HTMLDivElement>();
|
||||
|
||||
// Set App height and width.
|
||||
// Set App dimensions.
|
||||
useEffect(() => {
|
||||
dispatch(setAppDimensions({ height: appHeight, width: appWidth }));
|
||||
dispatch(setDimensions({
|
||||
name: "app",
|
||||
dimensions: { height: appHeight, width: appWidth },
|
||||
}));
|
||||
}, [appHeight, appWidth]);
|
||||
|
||||
// Set MainMenu height.
|
||||
// Set MainMenu dimensions.
|
||||
useEffect(() => {
|
||||
dispatch(setMenuDimensions({ height: mainMenuHeight }));
|
||||
}, [mainMenuHeight]);
|
||||
dispatch(setDimensions({
|
||||
name: "mainMenu",
|
||||
dimensions: { height: mainMenuHeight, width: mainMenuWidth },
|
||||
}));
|
||||
}, [mainMenuHeight, mainMenuWidth]);
|
||||
|
||||
return (
|
||||
<div className="App" ref={appRef}>
|
||||
|
||||
@@ -2,10 +2,10 @@ import { useSelector } from "react-redux";
|
||||
|
||||
import { FullScreenContainer } from "../Common/FullScreenContainer.styled";
|
||||
import { Layout } from "./Layout";
|
||||
import { menuDimensionsSelector } from "../../features/pageDimensions/pageDimensionsSelector";
|
||||
import { mainMenuDimensionsSelector } from "../../features/pageDimensions/pageDimensionsSelector";
|
||||
|
||||
export default function Broadcast() {
|
||||
const { height } = useSelector(menuDimensionsSelector);
|
||||
const { height } = useSelector(mainMenuDimensionsSelector);
|
||||
|
||||
return (
|
||||
<FullScreenContainer minHeight={700} minWidth={900} heightCutoff={height}>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { AnimatedBG } from "../../../../types/state";
|
||||
|
||||
import {
|
||||
ToggleContainer,
|
||||
ToggleBody,
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
export type ToggleProps = {
|
||||
label: string,
|
||||
toggled: boolean,
|
||||
onToggle: (value: AnimatedBG) => void,
|
||||
onToggle: (value: boolean) => void, // eslint-disable-line no-unused-vars
|
||||
showIndicators?: boolean,
|
||||
};
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useState } from "react";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { PadBox } from "@bedrock-layout/padbox";
|
||||
|
||||
import { appDimensionsSelector } from "../../../features/pageDimensions/pageDimensionsSelector";
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
import {
|
||||
initNewOverlayItem,
|
||||
@@ -22,17 +21,15 @@ export function OverlayControl() {
|
||||
|
||||
|
||||
/* For prototyping use only */
|
||||
const { width: appWidth, height: appHeight } = useSelector(appDimensionsSelector);
|
||||
const [overlayId, setOverlayId] = useState("foo_1.00000");
|
||||
const { width, height } = useSelector(appDimensionsSelector);
|
||||
|
||||
const getRandomArbitrary = (min: number, max: number) =>
|
||||
Math.random() * (max - min) + min;
|
||||
|
||||
const posRandomizer = () => {
|
||||
dispatch(setPosition({
|
||||
x: Math.floor(getRandomArbitrary(50, width - 50)),
|
||||
y: Math.floor(getRandomArbitrary(50, height - 50)),
|
||||
x: Math.floor(getRandomArbitrary(-50, 850)),
|
||||
y: Math.floor(getRandomArbitrary(-50, 650)),
|
||||
}));
|
||||
};
|
||||
const idRandomizer = () => {
|
||||
@@ -48,10 +45,12 @@ export function OverlayControl() {
|
||||
if (currentOverlayItem == null) {
|
||||
dispatch(initNewOverlayItem({
|
||||
overlayId,
|
||||
appDimensions: { height: appHeight, width: appWidth },
|
||||
initialPosition: { x: 400, y: 300 },
|
||||
setVisible: true,
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
dispatch(setVisibility(value));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,11 +4,17 @@ import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSe
|
||||
import { OverlayItemContainer } from "./styles";
|
||||
|
||||
export function OverlayDisplay() {
|
||||
const { currentOverlayItem } = useSelector(overlayToolSelector);
|
||||
const { currentOverlayItem, visible } = useSelector(overlayToolSelector);
|
||||
|
||||
if (currentOverlayItem == null) return null;
|
||||
|
||||
const { id, position } = currentOverlayItem;
|
||||
|
||||
return (
|
||||
<OverlayItemContainer position={position}>
|
||||
<OverlayItemContainer
|
||||
position={position}
|
||||
visible={visible}
|
||||
>
|
||||
{id}
|
||||
<br />
|
||||
({position.x}px {position.y}px)
|
||||
|
||||
@@ -3,16 +3,21 @@ import { OverlayPosition } from "../../../types/state";
|
||||
|
||||
export type OverlayItemContainerProps = {
|
||||
position: OverlayPosition,
|
||||
visible: boolean,
|
||||
};
|
||||
export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(({
|
||||
position: { x, y },
|
||||
visible,
|
||||
}) => ({
|
||||
style: {
|
||||
top: y,
|
||||
left: x,
|
||||
display: visible ? undefined : "none",
|
||||
},
|
||||
}))<OverlayItemContainerProps>`
|
||||
position: absolute;
|
||||
|
||||
/* Temporary. Overlay will be transparent and based on an image. */
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
background-color: white;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { workspaceSelector } from "../../../features/workspace/workspaceSelector
|
||||
import { PreviewWindow, H2, ControlsContainer } from "./styles";
|
||||
import { WorkspaceControls } from "./WorkspaceControls";
|
||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
||||
import { OverlayDisplay } from "../../OverlayTool";
|
||||
|
||||
import { workspaceObject } from "../workspaces";
|
||||
|
||||
@@ -28,6 +29,7 @@ export const Workspace = () => {
|
||||
height="300px"
|
||||
width="400px"
|
||||
>Preview Item</MockupBlock>
|
||||
<OverlayDisplay />
|
||||
</PreviewWindow>
|
||||
<ControlsContainer>
|
||||
<WorkspaceControls />
|
||||
|
||||
@@ -3,7 +3,6 @@ import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
||||
import { setAnimatedBG } from "../../../features/workspace/workspaceSlice";
|
||||
import { AnimatedBG } from "../../../types/state";
|
||||
|
||||
import { Toggle } from "../../Common/Inputs/Toggle";
|
||||
import { OverlayControl } from "../../OverlayTool";
|
||||
@@ -17,7 +16,7 @@ export const WorkspaceControls = () => {
|
||||
<Toggle
|
||||
label="Animate BG"
|
||||
toggled={animatedBG}
|
||||
onToggle={(value: AnimatedBG) => {
|
||||
onToggle={(value: boolean) => {
|
||||
dispatch(setAnimatedBG(value));
|
||||
}} />
|
||||
<OverlayControl />
|
||||
|
||||
@@ -16,6 +16,7 @@ export type PreviewWindowProps = {
|
||||
export const PreviewWindow = styled(PadBox).attrs(() => ({
|
||||
padding: "lg",
|
||||
}))<PreviewWindowProps>`
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,27 +1,49 @@
|
||||
import { useSelector } from "react-redux";
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Outlet } from "react-router-dom";
|
||||
|
||||
import { menuDimensionsSelector } from "../../features/pageDimensions/pageDimensionsSelector";
|
||||
import { mainMenuDimensionsSelector } from "../../features/pageDimensions/pageDimensionsSelector";
|
||||
import { useDimensions } from "../../utils/hooks";
|
||||
import { setDimensions } from "../../features/pageDimensions/pageDimensionsSlice";
|
||||
|
||||
import { FullScreenContainer } from "../Common/FullScreenContainer.styled";
|
||||
import { WorkspaceList } from "./WorkspaceList";
|
||||
import { LayoutGrid, LayoutGridItem } from "../Common/LayoutGrid.styled";
|
||||
import { OverlayDisplay } from "../OverlayTool";
|
||||
|
||||
const WORKSPACE_LIST_WIDTH = 180;
|
||||
|
||||
export default function Workspaces() {
|
||||
const { height } = useSelector(menuDimensionsSelector);
|
||||
const { height } = useSelector(mainMenuDimensionsSelector);
|
||||
const dispatch = useDispatch();
|
||||
const [workspaceRef, {
|
||||
height: workspaceHeight,
|
||||
width: workspaceWidth,
|
||||
}] = useDimensions<HTMLDivElement>();
|
||||
|
||||
// Set Workspace dimensions.
|
||||
useEffect(() => {
|
||||
dispatch(setDimensions({
|
||||
name: "workspace",
|
||||
dimensions: { height: workspaceHeight, width: workspaceWidth },
|
||||
}));
|
||||
}, [workspaceHeight, workspaceWidth]);
|
||||
|
||||
return (
|
||||
<FullScreenContainer minHeight={700} minWidth={900} heightCutoff={height}>
|
||||
<LayoutGrid columns={["180px", 1]} rows={1}>
|
||||
<LayoutGrid columns={[`${WORKSPACE_LIST_WIDTH}px`, 1]} rows={1}>
|
||||
<LayoutGridItem column={1} row={1}>
|
||||
<WorkspaceList headerOffset={height} />
|
||||
</LayoutGridItem>
|
||||
<LayoutGridItem column={2} row={1}>
|
||||
<FullScreenContainer
|
||||
ref={workspaceRef}
|
||||
minHeight={700}
|
||||
minWidth={900}
|
||||
heightCutoff={height}
|
||||
widthCutoff={WORKSPACE_LIST_WIDTH}
|
||||
>
|
||||
<Outlet />
|
||||
<OverlayDisplay />
|
||||
</FullScreenContainer>
|
||||
</LayoutGridItem>
|
||||
</LayoutGrid>
|
||||
</FullScreenContainer>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
RootState,
|
||||
OverlayPosition,
|
||||
OverlayId,
|
||||
AppDimensions,
|
||||
} from "../../types/state";
|
||||
|
||||
const initialState: RootState["overlayTool"] = {
|
||||
@@ -16,13 +15,10 @@ const initialState: RootState["overlayTool"] = {
|
||||
|
||||
const makeNewOverlayItem = (
|
||||
overlayId: OverlayId,
|
||||
appDimensions: AppDimensions,
|
||||
initialPosition: OverlayPosition,
|
||||
) => ({
|
||||
id: overlayId,
|
||||
position: {
|
||||
x: appDimensions.width / 2,
|
||||
y: appDimensions.height / 2,
|
||||
},
|
||||
position: initialPosition,
|
||||
opacity: 1,
|
||||
scale: 1,
|
||||
});
|
||||
@@ -30,7 +26,8 @@ const makeNewOverlayItem = (
|
||||
|
||||
type InitNewOverlayItemAction = {
|
||||
overlayId: OverlayId,
|
||||
appDimensions: AppDimensions,
|
||||
initialPosition: OverlayPosition,
|
||||
setVisible: boolean,
|
||||
};
|
||||
|
||||
export const overlayToolSlice = createSlice({
|
||||
@@ -41,9 +38,10 @@ export const overlayToolSlice = createSlice({
|
||||
if (state.currentOverlayItem == null) {
|
||||
state.currentOverlayItem = makeNewOverlayItem(
|
||||
action.payload.overlayId,
|
||||
action.payload.appDimensions,
|
||||
action.payload.initialPosition,
|
||||
);
|
||||
state.currentOverlayId = action.payload.overlayId;
|
||||
state.visible = action.payload.setVisible;
|
||||
}
|
||||
},
|
||||
setVisibility: (state, action: PayloadAction<boolean>) => {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { RootState } from "../../types/state";
|
||||
|
||||
export const menuDimensionsSelector = (state: RootState) =>
|
||||
state.pageDimensions.menu;
|
||||
export const mainMenuDimensionsSelector = (state: RootState) =>
|
||||
state.pageDimensions.mainMenu;
|
||||
export const appDimensionsSelector = (state: RootState) =>
|
||||
state.pageDimensions.app;
|
||||
export const workspaceDimensionsSelector = (state: RootState) =>
|
||||
state.pageDimensions.workspace;
|
||||
@@ -1,29 +1,27 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
import { RootState, MenuDimensions, AppDimensions } from "../../types/state";
|
||||
import { RootState, Dimensions } from "../../types/state";
|
||||
|
||||
const initialState: RootState["pageDimensions"] = {
|
||||
menu: {
|
||||
height: 0,
|
||||
},
|
||||
app: {
|
||||
height: 0,
|
||||
width: 0,
|
||||
},
|
||||
mainMenu: { height: 0, width: 0 },
|
||||
app: { height: 0, width: 0 },
|
||||
workspace: { height: 0, width: 0 },
|
||||
};
|
||||
|
||||
type SetDimensionsAction = {
|
||||
name: "mainMenu" | "app" | "workspace",
|
||||
dimensions: Dimensions,
|
||||
};
|
||||
|
||||
export const pageDimensionsSlice = createSlice({
|
||||
name: "pageDimensions",
|
||||
initialState,
|
||||
reducers: {
|
||||
setMenuDimensions: (state, action: PayloadAction<MenuDimensions>) => {
|
||||
state.menu = action.payload;
|
||||
},
|
||||
setAppDimensions: (state, action: PayloadAction<AppDimensions>) => {
|
||||
state.app = action.payload;
|
||||
setDimensions: (state, action: PayloadAction<SetDimensionsAction>) => {
|
||||
state[action.payload.name] = action.payload.dimensions;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setMenuDimensions, setAppDimensions } = pageDimensionsSlice.actions;
|
||||
export const { setDimensions } = pageDimensionsSlice.actions;
|
||||
export default pageDimensionsSlice.reducer;
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { RootState, WorkspaceId, AnimatedBG } from "../../types/state";
|
||||
import { RootState, WorkspaceId } from "../../types/state";
|
||||
|
||||
const initialState: RootState["workspace"] = {
|
||||
workspaceId: "",
|
||||
@@ -13,7 +13,7 @@ export const workspaceSlice = createSlice({
|
||||
setWorkspaceId: (state, action: PayloadAction<WorkspaceId>) => {
|
||||
state.workspaceId = action.payload;
|
||||
},
|
||||
setAnimatedBG: (state, action: PayloadAction<AnimatedBG>) => {
|
||||
setAnimatedBG: (state, action: PayloadAction<boolean>) => {
|
||||
state.animatedBG = action.payload;
|
||||
},
|
||||
},
|
||||
|
||||
Vendored
+5
-12
@@ -6,26 +6,19 @@ export type RootState = {
|
||||
|
||||
// Page Dimensions
|
||||
export type PageDimensions = {
|
||||
menu: MenuDimensions,
|
||||
app: AppDimensions,
|
||||
};
|
||||
|
||||
export type MenuDimensions = {
|
||||
height: number,
|
||||
};
|
||||
export type AppDimensions = {
|
||||
height: number,
|
||||
width: number,
|
||||
mainMenu: Dimensions,
|
||||
app: Dimensions,
|
||||
workspace: Dimensions,
|
||||
};
|
||||
export type Dimensions = { width: number, height: number };
|
||||
|
||||
// Workspace
|
||||
export type Workspace = {
|
||||
workspaceId: WorkspaceId,
|
||||
animatedBG: AnimatedBG,
|
||||
animatedBG: boolean,
|
||||
};
|
||||
|
||||
export type WorkspaceId = string;
|
||||
export type AnimatedBG = boolean;
|
||||
|
||||
// Overlay Tool
|
||||
export type OverlayTool = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"importHelpers": true,
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
|
||||
Reference in new issue
Block a user