Skip to content

Commit

Permalink
fix: generating preview in layers panel (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjuanes authored Oct 13, 2024
1 parent c19e427 commit 9e5fd96
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/components/panels/layers.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import React from "react";
import {useUpdate} from "react-use";
import classNames from "classnames";
import {StackIcon, renderIcon, CheckIcon, ChevronDownIcon, ChevronRightIcon} from "@josemi-icons/react";
import {renderIcon, CheckIcon, ChevronDownIcon, ChevronRightIcon} from "@josemi-icons/react";
import {Panel} from "../ui/panel.jsx";
import {themed} from "../../contexts/theme.jsx";
import {useScene} from "../../contexts/scene.jsx";
import {exportToDataURL} from "../../export.js";
import {FIELDS, TRANSPARENT} from "../../constants.js";
import transparentBg from "../../assets/transparent.svg";

// Layers preview variables
const LAYER_PREVIEW_SIZE = 32;
const LAYER_PREVIEW_BACKGROUND = TRANSPARENT;

// Tiny hook to generate the preview of the element
const useElementPreview = (elements, dependencies = []) => {
const [previewImage, setPreviewImage] = React.useState(null);
React.useEffect(() => {
if (elements.length > 1 || !elements[0]?.[FIELDS.CREATING]) {
const previewOptions = {
elements: elements,
width: 32,
height: 32,
background: TRANSPARENT,
width: LAYER_PREVIEW_SIZE,
height: LAYER_PREVIEW_SIZE,
background: LAYER_PREVIEW_BACKGROUND,
};
exportToDataURL(previewOptions).then(image => {
setPreviewImage(image);
exportToDataURL(elements, previewOptions).then(image => {
return setPreviewImage(image);
});
}
}, dependencies);
Expand Down

0 comments on commit 9e5fd96

Please sign in to comment.