Skip to content

Commit c9fb6fa

Browse files
mimic optimizations & style fix
1 parent bf830d6 commit c9fb6fa

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

editor/scaffolds/canvas/canvas.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export function VisualContentArea() {
3232
const [mode, setMode] = useState<"full" | "isolate">("full");
3333

3434
return (
35-
<CanvasContainer ref={canvasSizingRef} id="canvas">
35+
<CanvasContainer
36+
ref={canvasSizingRef}
37+
id="canvas"
38+
maxWidth={mode == "isolate" ? "calc((100vw - 200px) * 0.6)" : "100%"} // TODO: make this dynamic
39+
>
3640
{/* <EditorAppbarFragments.Canvas /> */}
3741

3842
{isEmptyPage ? (
@@ -90,8 +94,11 @@ export function VisualContentArea() {
9094
);
9195
}
9296

93-
const CanvasContainer = styled.div`
97+
const CanvasContainer = styled.div<{
98+
maxWidth?: string;
99+
}>`
94100
display: flex;
95101
flex-direction: column;
102+
max-width: ${(p) => p.maxWidth};
96103
height: 100%;
97104
`;

editor/scaffolds/preview/index.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import { remote } from "@design-sdk/figma";
1515
const DEV_ONLY_FIGMA_PAT =
1616
process.env.NEXT_PUBLIC_DEVELOPER_FIGMA_PERSONAL_ACCESS_TOKEN;
1717

18+
const placeholderimg =
19+
"https://bridged-service-static.s3.us-west-1.amazonaws.com/placeholder-images/image-placeholder-bw-tile-100.png";
20+
1821
const build_config: config.BuildConfiguration = {
1922
...config.default_build_configuration,
2023
disable_components: true,
@@ -78,7 +81,7 @@ export function Preview({
7881
}
7982

8083
const d2c_firstload = () => {
81-
designToCode({
84+
return designToCode({
8285
input: _input,
8386
build_config: build_config,
8487
framework: framework_config,
@@ -87,17 +90,10 @@ export function Preview({
8790
asset_repository: MainImageRepository.instance,
8891
custom_asset_replacement: {
8992
type: "static",
90-
resource:
91-
"https://bridged-service-static.s3.us-west-1.amazonaws.com/placeholder-images/image-placeholder-bw-tile-100.png",
93+
resource: placeholderimg,
9294
},
9395
},
94-
})
95-
.then((r) => {
96-
on_preview_result(r, false);
97-
})
98-
.catch((e) => {
99-
console.error("error while making first paint preview.", e);
100-
});
96+
});
10197
};
10298

10399
const d2c_imageload = () => {
@@ -139,8 +135,14 @@ export function Preview({
139135
}
140136
} else {
141137
if (_input) {
142-
d2c_firstload();
143-
d2c_imageload();
138+
d2c_firstload().then((r) => {
139+
on_preview_result(r, false);
140+
// if the result contains a image and needs to be fetched,
141+
if (r.code.raw.includes(placeholderimg)) {
142+
// TODO: we don't yet have other way to know if image is used, other than checking if placeholder image is used. - this needs to be updated in d2c module to include used images meta in the result.
143+
d2c_imageload();
144+
}
145+
});
144146
}
145147
}
146148
}, [target?.id]);

0 commit comments

Comments
 (0)