From df868f11260b7746e3eb2914d7b5b8165a8da131 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Fri, 14 Jan 2022 15:17:23 -0500 Subject: [PATCH] ISSUE-025 - Partial failure. Realized that maybe the only way to get the dimensions of the loaded images is to measure them and include them with the file name definitions. To load an image at the center of the element would require writing information at the same time we read it. It's not a race condition; it's more like the chicken and the egg. I'm sure, if I really wanted to, I could find a two step process of loading at 0 opacity, finding the dimensions, and then moving it to the center and revealing it. But I don't have the desire. Still. I went ahead and added workspace properties to the central state and read from them when it makes sense. --- .../Workspaces/Workspace/Workspace.tsx | 20 +++++++++-------- .../WorkspaceList/WorkspaceList.tsx | 6 ++--- src/components/Workspaces/workspaces.ts | 12 ++++------ src/features/workspace/workspaceSlice.ts | 22 +++++++++++++++++-- src/types/state.d.ts | 6 +++++ 5 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/components/Workspaces/Workspace/Workspace.tsx b/src/components/Workspaces/Workspace/Workspace.tsx index 7a79ae0..2fac558 100644 --- a/src/components/Workspaces/Workspace/Workspace.tsx +++ b/src/components/Workspaces/Workspace/Workspace.tsx @@ -5,7 +5,7 @@ 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 { updateWorkspace } from "../../../features/workspace/workspaceSlice"; import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector"; import { newWorkspace } from "../../../features/overlayTool/overlayToolSlice"; @@ -14,31 +14,33 @@ import { WorkspaceControls } from "./WorkspaceControls"; import { MockupBlock } from "../../Common/MockupBlock.styled"; import { OverlayDisplay } from "../../OverlayTool"; -import { workspaceObject } from "../workspaces"; +import { workspaces } from "../workspaces"; export const Workspace = () => { const dispatch = useDispatch(); const { workspaceId } = useParams(); - const { animatedBG } = useSelector(workspaceSelector); + const { animatedBG, workspaceProperties } = useSelector(workspaceSelector); const { currentWorkspaceId: overlayWorkspaceId } = useSelector(overlayToolSelector); useEffect(() => { if (workspaceId == null) return; // Update workspace store for ID. - dispatch(setWorkspaceId(workspaceId)); + dispatch(updateWorkspace({ + workspaceId, + workspaceProperties: workspaces[workspaceId], + })); // Switching Workspace means we need to init a newWorkspace for Overlay tool. if (overlayWorkspaceId !== workspaceId) { dispatch(newWorkspace({ - overlayIds: workspaceObject[workspaceId].overlayIds, + overlayIds: workspaces[workspaceId].overlayIds, workspaceId: workspaceId, })); } }, [workspaceId]); if (workspaceId == null) return null; - const workspace = workspaceObject[workspaceId]; return ( { maxWidth="80%" centerChildren > -

{workspaceId ? workspace.name : "Unknown"}

+

{workspaceId ? workspaceProperties.name : "Unknown"}

{ width="100px" >Preview Item diff --git a/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx b/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx index bc5c27d..8f3e63c 100644 --- a/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx +++ b/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx @@ -5,13 +5,13 @@ import { WorkspaceListBox } from "./styles"; import { Stack } from "@bedrock-layout/stack"; import { MenuItem } from "../../Common/MenuItem.styled"; -import { workspaceObject } from "../workspaces"; +import { workspaces } from "../workspaces"; type WorkspaceListProps = { headerOffset?: number, }; export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => { - const workspaceList = _.keys(workspaceObject); + const workspaceList = _.keys(workspaces); return ( @@ -19,7 +19,7 @@ export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => { ))} diff --git a/src/components/Workspaces/workspaces.ts b/src/components/Workspaces/workspaces.ts index db93ab1..d4c8fde 100644 --- a/src/components/Workspaces/workspaces.ts +++ b/src/components/Workspaces/workspaces.ts @@ -1,13 +1,9 @@ -import { Dimensions, OverlayIds } from "../../types/state"; +import { WorkspaceProperties } from "../../types/state"; -export type WorkspaceObject = { - [id: string]: { - name: string, - overlayIds: OverlayIds, - previewWindowDimensions: Dimensions, - }, +type WorkspaceObject = { + [id: string]: WorkspaceProperties, }; -export const workspaceObject: WorkspaceObject = { +export const workspaces: WorkspaceObject = { chyronSimple: { name: "Chyron Simple", overlayIds: [ diff --git a/src/features/workspace/workspaceSlice.ts b/src/features/workspace/workspaceSlice.ts index 4abc2e0..9913f80 100644 --- a/src/features/workspace/workspaceSlice.ts +++ b/src/features/workspace/workspaceSlice.ts @@ -1,9 +1,19 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { RootState, WorkspaceId } from "../../types/state"; +import { RootState, WorkspaceId, WorkspaceProperties } from "../../types/state"; const initialState: RootState["workspace"] = { workspaceId: "", animatedBG: true, + workspaceProperties: { + name: "undefined", + overlayIds: [], + previewWindowDimensions: { width: 0, height: 0 }, + }, +}; + +export type UpdateWorkspaceAction = { + workspaceId: WorkspaceId, + workspaceProperties: WorkspaceProperties, }; export const workspaceSlice = createSlice({ @@ -16,8 +26,16 @@ export const workspaceSlice = createSlice({ setAnimatedBG: (state, action: PayloadAction) => { state.animatedBG = action.payload; }, + updateWorkspace: (state, action: PayloadAction) => { + state.workspaceId = action.payload.workspaceId; + state.workspaceProperties = action.payload.workspaceProperties; + }, }, }); -export const { setWorkspaceId, setAnimatedBG } = workspaceSlice.actions; +export const { + setWorkspaceId, + setAnimatedBG, + updateWorkspace, +} = workspaceSlice.actions; export default workspaceSlice.reducer; diff --git a/src/types/state.d.ts b/src/types/state.d.ts index 0d7d47f..de6fb3f 100644 --- a/src/types/state.d.ts +++ b/src/types/state.d.ts @@ -16,9 +16,15 @@ export type Dimensions = { width: number, height: number }; export type Workspace = { workspaceId: WorkspaceId, animatedBG: boolean, + workspaceProperties: WorkspaceProperties, }; export type WorkspaceId = string; +export type WorkspaceProperties = { + name: string, + overlayIds: OverlayIds, + previewWindowDimensions: Dimensions, +}; // Overlay Tool export type OverlayTool = {