Skip to content

Commit

Permalink
fix: Don't draw orange border when re-rendering screenshot (#120)
Browse files Browse the repository at this point in the history
* fix: Don't need to draw a border around the img

Not in the final designs

* fix: inadvertant effects

* The effect to draw the annotation was executing unnecessarily. Give the
effect a proper list of dependencies to prevent unnecessary calls.
* Properly cleanup event handler in the case the effect does run again.
  • Loading branch information
mhan83 authored Oct 11, 2024
1 parent 4eb088b commit e08edb2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions webview-ui/test-generation/src/Screenshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export function Screenshot(props: ScreenshotProps) {
if (!context) {
return;
}

const img = new Image();
img.src = src;

img.onload = () => {
const onload = () => {
context.drawImage(img, 0, 0, imgWidth, imgHeight);

context.strokeRect(0, 0, imgWidth, imgHeight);

if (annotation) {
context.lineWidth = 3;
context.rect(
Expand All @@ -46,6 +45,18 @@ export function Screenshot(props: ScreenshotProps) {
context.stroke();
}
};
}, [ref, annotation, src, imgWidth, imgHeight]);
img.addEventListener('load', onload);

return () => img.removeEventListener('load', onload);
}, [
ref,
annotation.x,
annotation.y,
annotation.width,
annotation.height,
src,
imgWidth,
imgHeight,
]);
return <canvas ref={ref} width={imgWidth} height={imgHeight} />;
}

0 comments on commit e08edb2

Please sign in to comment.