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 { 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 (
|
||||
<Stack
|
||||
@@ -47,9 +49,9 @@ export const Workspace = () => {
|
||||
maxWidth="80%"
|
||||
centerChildren
|
||||
>
|
||||
<H2>{workspaceId ? workspace.name : "Unknown"}</H2>
|
||||
<H2>{workspaceId ? workspaceProperties.name : "Unknown"}</H2>
|
||||
<PreviewWindow
|
||||
dimensions={workspace.previewWindowDimensions}
|
||||
dimensions={workspaceProperties.previewWindowDimensions}
|
||||
animatedBG={animatedBG}
|
||||
>
|
||||
<MockupBlock
|
||||
@@ -58,7 +60,7 @@ export const Workspace = () => {
|
||||
width="100px"
|
||||
>Preview Item</MockupBlock>
|
||||
<OverlayDisplay
|
||||
containerDimensions={workspace.previewWindowDimensions}
|
||||
containerDimensions={workspaceProperties.previewWindowDimensions}
|
||||
/>
|
||||
</PreviewWindow>
|
||||
<ControlsContainer>
|
||||
|
||||
@@ -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 (
|
||||
<WorkspaceListBox headerOffset={headerOffset}>
|
||||
<Stack as="ul" gutter="md">
|
||||
@@ -19,7 +19,7 @@ export const WorkspaceList = ({ headerOffset }: WorkspaceListProps) => {
|
||||
<WorkspaceListNavLink
|
||||
key={id}
|
||||
to={id}
|
||||
label={workspaceObject[id].name}
|
||||
label={workspaces[id].name}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
|
||||
@@ -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: [
|
||||
|
||||
Reference in new issue
Block a user