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.
This commit is contained in:
1 parent
1ca2137a5b
commit
df868f1126
5 files changed
+44
-22
No files matched your search
@@ -5,7 +5,7 @@ import { Center } from "@bedrock-layout/center";
|
|||||||
import { Stack } from "@bedrock-layout/stack";
|
import { Stack } from "@bedrock-layout/stack";
|
||||||
|
|
||||||
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
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 { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||||
import { newWorkspace } from "../../../features/overlayTool/overlayToolSlice";
|
import { newWorkspace } from "../../../features/overlayTool/overlayToolSlice";
|
||||||
|
|
||||||
@@ -14,31 +14,33 @@ import { WorkspaceControls } from "./WorkspaceControls";
|
|||||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
||||||
import { OverlayDisplay } from "../../OverlayTool";
|
import { OverlayDisplay } from "../../OverlayTool";
|
||||||
|
|
||||||
import { workspaceObject } from "../workspaces";
|
import { workspaces } from "../workspaces";
|
||||||
|
|
||||||
export const Workspace = () => {
|
export const Workspace = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { workspaceId } = useParams();
|
const { workspaceId } = useParams();
|
||||||
const { animatedBG } = useSelector(workspaceSelector);
|
const { animatedBG, workspaceProperties } = useSelector(workspaceSelector);
|
||||||
const { currentWorkspaceId: overlayWorkspaceId } = useSelector(overlayToolSelector);
|
const { currentWorkspaceId: overlayWorkspaceId } = useSelector(overlayToolSelector);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (workspaceId == null) return;
|
if (workspaceId == null) return;
|
||||||
|
|
||||||
// Update workspace store for ID.
|
// 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.
|
// Switching Workspace means we need to init a newWorkspace for Overlay tool.
|
||||||
if (overlayWorkspaceId !== workspaceId) {
|
if (overlayWorkspaceId !== workspaceId) {
|
||||||
dispatch(newWorkspace({
|
dispatch(newWorkspace({
|
||||||
overlayIds: workspaceObject[workspaceId].overlayIds,
|
overlayIds: workspaces[workspaceId].overlayIds,
|
||||||
workspaceId: workspaceId,
|
workspaceId: workspaceId,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}, [workspaceId]);
|
}, [workspaceId]);
|
||||||
|
|
||||||
if (workspaceId == null) return null;
|
if (workspaceId == null) return null;
|
||||||
const workspace = workspaceObject[workspaceId];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
@@ -47,9 +49,9 @@ export const Workspace = () => {
|
|||||||
maxWidth="80%"
|
maxWidth="80%"
|
||||||
centerChildren
|
centerChildren
|
||||||
>
|
>
|
||||||
<H2>{workspaceId ? workspace.name : "Unknown"}</H2>
|
<H2>{workspaceId ? workspaceProperties.name : "Unknown"}</H2>
|
||||||
<PreviewWindow
|
<PreviewWindow
|
||||||
dimensions={workspace.previewWindowDimensions}
|
dimensions={workspaceProperties.previewWindowDimensions}
|
||||||
animatedBG={animatedBG}
|
animatedBG={animatedBG}
|
||||||
>
|
>
|
||||||
<MockupBlock
|
<MockupBlock
|
||||||
@@ -58,7 +60,7 @@ export const Workspace = () => {
|
|||||||
width="100px"
|
width="100px"
|
||||||
>Preview Item</MockupBlock>
|
>Preview Item</MockupBlock>
|
||||||
<OverlayDisplay
|
<OverlayDisplay
|
||||||
containerDimensions={workspace.previewWindowDimensions}
|
containerDimensions={workspaceProperties.previewWindowDimensions}
|
||||||
/>
|
/>
|
||||||
</PreviewWindow>
|
</PreviewWindow>
|
||||||
<ControlsContainer>
|
<ControlsContainer>
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import { WorkspaceListBox } from "./styles";
|
|||||||
import { Stack } from "@bedrock-layout/stack";
|
import { Stack } from "@bedrock-layout/stack";
|
||||||
import { MenuItem } from "../../Common/MenuItem.styled";
|
import { MenuItem } from "../../Common/MenuItem.styled";
|
||||||
|
|
||||||
import { workspaceObject } from "../workspaces";
|
import { workspaces } from "../workspaces";
|
||||||
|
|
||||||
type WorkspaceListProps = {
|
type WorkspaceListProps = {
|
||||||
headerOffset?: number,
|
headerOffset?: number,
|
||||||
};
|
};
|
||||||
export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
|
export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
|
||||||
const workspaceList = _.keys(workspaceObject);
|
const workspaceList = _.keys(workspaces);
|
||||||
return (
|
return (
|
||||||
<WorkspaceListBox headerOffset={headerOffset}>
|
<WorkspaceListBox headerOffset={headerOffset}>
|
||||||
<Stack as="ul" gutter="md">
|
<Stack as="ul" gutter="md">
|
||||||
@@ -19,7 +19,7 @@ export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
|
|||||||
<WorkspaceListNavLink
|
<WorkspaceListNavLink
|
||||||
key={id}
|
key={id}
|
||||||
to={id}
|
to={id}
|
||||||
label={workspaceObject[id].name}
|
label={workspaces[id].name}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { Dimensions, OverlayIds } from "../../types/state";
|
import { WorkspaceProperties } from "../../types/state";
|
||||||
|
|
||||||
export type WorkspaceObject = {
|
type WorkspaceObject = {
|
||||||
[id: string]: {
|
[id: string]: WorkspaceProperties,
|
||||||
name: string,
|
|
||||||
overlayIds: OverlayIds,
|
|
||||||
previewWindowDimensions: Dimensions,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
export const workspaceObject: WorkspaceObject = {
|
export const workspaces: WorkspaceObject = {
|
||||||
chyronSimple: {
|
chyronSimple: {
|
||||||
name: "Chyron Simple",
|
name: "Chyron Simple",
|
||||||
overlayIds: [
|
overlayIds: [
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
import { RootState, WorkspaceId } from "../../types/state";
|
import { RootState, WorkspaceId, WorkspaceProperties } from "../../types/state";
|
||||||
|
|
||||||
const initialState: RootState["workspace"] = {
|
const initialState: RootState["workspace"] = {
|
||||||
workspaceId: "",
|
workspaceId: "",
|
||||||
animatedBG: true,
|
animatedBG: true,
|
||||||
|
workspaceProperties: {
|
||||||
|
name: "undefined",
|
||||||
|
overlayIds: [],
|
||||||
|
previewWindowDimensions: { width: 0, height: 0 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UpdateWorkspaceAction = {
|
||||||
|
workspaceId: WorkspaceId,
|
||||||
|
workspaceProperties: WorkspaceProperties,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const workspaceSlice = createSlice({
|
export const workspaceSlice = createSlice({
|
||||||
@@ -16,8 +26,16 @@ export const workspaceSlice = createSlice({
|
|||||||
setAnimatedBG: (state, action: PayloadAction<boolean>) => {
|
setAnimatedBG: (state, action: PayloadAction<boolean>) => {
|
||||||
state.animatedBG = action.payload;
|
state.animatedBG = action.payload;
|
||||||
},
|
},
|
||||||
|
updateWorkspace: (state, action: PayloadAction<UpdateWorkspaceAction>) => {
|
||||||
|
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;
|
export default workspaceSlice.reducer;
|
||||||
Vendored
+6
@@ -16,9 +16,15 @@ export type Dimensions = { width: number, height: number };
|
|||||||
export type Workspace = {
|
export type Workspace = {
|
||||||
workspaceId: WorkspaceId,
|
workspaceId: WorkspaceId,
|
||||||
animatedBG: boolean,
|
animatedBG: boolean,
|
||||||
|
workspaceProperties: WorkspaceProperties,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WorkspaceId = string;
|
export type WorkspaceId = string;
|
||||||
|
export type WorkspaceProperties = {
|
||||||
|
name: string,
|
||||||
|
overlayIds: OverlayIds,
|
||||||
|
previewWindowDimensions: Dimensions,
|
||||||
|
};
|
||||||
|
|
||||||
// Overlay Tool
|
// Overlay Tool
|
||||||
export type OverlayTool = {
|
export type OverlayTool = {
|
||||||
|
|||||||
Reference in new issue
Block a user