Skip to content

Commit

Permalink
feat: added processing status message
Browse files Browse the repository at this point in the history
  • Loading branch information
dendrofen committed Sep 16, 2023
1 parent 4ddf50a commit 6d1e497
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/ProcessButtons.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import styles from '@/app/page.module.css';
import { exportStageSVG } from "@/lib";
import { useCallback, useState } from "react";
import { startTransition, useCallback, useState } from "react";

export default function ProcessButtons() {
const [image, setImage] = useState();
const [isLoading, setLoading] = useState();

const onStageSVG = useCallback(async () => {
startTransition(() => {
setLoading(true);
})
const svg = await exportStageSVG(window.Konva.stages[0]);
setImage(svg);
setLoading(false);
}, [setImage])

const onNoImageSVG = useCallback(async () => {
startTransition(() => {
setLoading(true);
})
const stage = window.Konva.stages[0];
const imageNode = stage.getLayers()[0].findOne('Image');
const svg = await exportStageSVG(stage, false, {
onBefore: () => imageNode.hide(),
onAfter: () => imageNode.show()
});
setImage(svg);
setLoading(false);
}, [setImage])

return (
<>
{isLoading && <p>Processing...</p>}
<div className={styles.grid}>
<button type="button" onClick={onStageSVG}>Stage to SVG</button>
<button type="button" onClick={onNoImageSVG}>Without Image to SVG</button>
Expand Down

0 comments on commit 6d1e497

Please sign in to comment.