Skip to content

Commit 43be14b

Browse files
committed
PR comments
1 parent 3282a1d commit 43be14b

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

packages/feedback/src/screenshot/components/ScreenshotEditorv2.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const getContainedSize = (measurementDiv: HTMLDivElement, imageSource: HTMLCanva
6262
return { action: '', x: x, y: y, width: width, height: height };
6363
};
6464

65-
function drawRect(rect: Rect, ctx: CanvasRenderingContext2D, scale: number = 1, lineWidth: number = 4): void {
65+
function drawRect(rect: Rect, ctx: CanvasRenderingContext2D, scale: number = 1): void {
6666
const scaledX = rect.x * scale;
6767
const scaledY = rect.y * scale;
6868
const scaledWidth = rect.width * scale;
@@ -97,12 +97,13 @@ function drawRect(rect: Rect, ctx: CanvasRenderingContext2D, scale: number = 1,
9797
let strokeColor;
9898
const sentryFeedback = DOCUMENT.getElementById('sentry-feedback');
9999
if (sentryFeedback) {
100+
const computedStyle = getComputedStyle(sentryFeedback);
100101
strokeColor =
101-
getComputedStyle(sentryFeedback).getPropertyValue('--button-primary-background') ||
102-
getComputedStyle(sentryFeedback).getPropertyValue('--accent-background');
102+
computedStyle.getPropertyValue('--button-primary-background') ||
103+
computedStyle.getPropertyValue('--accent-background');
103104
}
104105
ctx.strokeStyle = strokeColor || 'white';
105-
ctx.lineWidth = lineWidth;
106+
ctx.lineWidth = 2;
106107
ctx.strokeRect(scaledX + 1, scaledY + 1, scaledWidth - 2, scaledHeight - 2);
107108
}
108109

@@ -138,6 +139,10 @@ export function ScreenshotEditorFactoryv2({
138139
const [scaleFactor, setScaleFactor] = hooks.useState<number>(1);
139140

140141
const resize = hooks.useCallback((): void => {
142+
if (!displayEditor) {
143+
return;
144+
}
145+
141146
const screenshotCanvas = screenshotRef.current;
142147
const graywashCanvas = graywashRef.current;
143148
const measurementDiv = measurementRef.current;
@@ -163,7 +168,7 @@ export function ScreenshotEditorFactoryv2({
163168
}
164169
screenshotContext.drawImage(imageSource, 0, 0, imageDimensions.width, imageDimensions.height);
165170
drawScene();
166-
}, [imageSource, drawCommands]);
171+
}, [imageSource, drawCommands, displayEditor]);
167172

168173
hooks.useEffect(() => {
169174
WINDOW.addEventListener('resize', resize);
@@ -175,7 +180,7 @@ export function ScreenshotEditorFactoryv2({
175180

176181
hooks.useLayoutEffect(() => {
177182
resize();
178-
}, [displayEditor]);
183+
}, [resize]);
179184

180185
hooks.useEffect(() => {
181186
drawScene();
@@ -212,13 +217,14 @@ export function ScreenshotEditorFactoryv2({
212217
grayCtx.fillRect(0, 0, imageBuffer.width, imageBuffer.height);
213218
}
214219

220+
grayCtx.lineWidth = 4;
215221
drawCommands.forEach(rect => {
216222
drawRect(rect, grayCtx);
217223
});
218224
ctx.drawImage(grayWashBufferBig, 0, 0);
219225
}
220226

221-
function drawScene(): void {
227+
const drawScene = hooks.useCallback((): void => {
222228
const graywashCanvas = graywashRef.current;
223229
if (!graywashCanvas) {
224230
return;
@@ -239,14 +245,13 @@ export function ScreenshotEditorFactoryv2({
239245

240246
const scale = graywashCanvas.clientWidth / imageBuffer.width;
241247
drawCommands.forEach(rect => {
242-
drawRect(rect, ctx, scale, 2);
248+
drawRect(rect, ctx, scale);
243249
});
244250

245251
if (currentRect) {
246-
drawRect(currentRect, ctx, 1, 2);
247-
setCurrentRect(undefined);
252+
drawRect(currentRect, ctx, 1);
248253
}
249-
}
254+
}, [drawCommands, currentRect]);
250255

251256
useTakeScreenshot({
252257
onBeforeScreenshot: hooks.useCallback(() => {
@@ -274,7 +279,7 @@ export function ScreenshotEditorFactoryv2({
274279
}, []),
275280
});
276281

277-
const onDraw = (e: MouseEvent): void => {
282+
const handleMouseDown = (e: MouseEvent): void => {
278283
const graywashCanvas = graywashRef.current;
279284
if (!action || !graywashCanvas) {
280285
return;
@@ -298,6 +303,7 @@ export function ScreenshotEditorFactoryv2({
298303
};
299304

300305
const handleMouseUp = (e: MouseEvent): void => {
306+
setCurrentRect(undefined);
301307
const endX = Math.max(0, Math.min(e.clientX - boundingRect.left, graywashCanvas.width / DPI));
302308
const endY = Math.max(0, Math.min(e.clientY - boundingRect.top, graywashCanvas.height / DPI));
303309
// prevent drawing rect when clicking on the canvas (ie. clicking delete)
@@ -334,8 +340,8 @@ export function ScreenshotEditorFactoryv2({
334340
<div class="editor__image-container">
335341
<div class="editor__canvas-container" ref={measurementRef}>
336342
<canvas ref={screenshotRef}></canvas>
337-
<canvas class="editor__canvas-annotate" ref={graywashRef} onMouseDown={onDraw}></canvas>
338-
<div class="editor__rect-container" ref={rectDivRef} onMouseDown={onDraw}>
343+
<canvas class="editor__canvas-annotate" ref={graywashRef} onMouseDown={handleMouseDown}></canvas>
344+
<div class="editor__rect-container" ref={rectDivRef} onMouseDown={handleMouseDown}>
339345
{drawCommands.map((rect, index) => (
340346
<div
341347
key={index}
@@ -346,7 +352,7 @@ export function ScreenshotEditorFactoryv2({
346352
width: `${rect.width * scaleFactor}px`,
347353
height: `${rect.height * scaleFactor}px`,
348354
}}
349-
onMouseDown={onDraw}
355+
onMouseDown={handleMouseDown}
350356
>
351357
<button type="button" onClick={() => handleDeleteRect(index)}>
352358
<IconClose />

packages/feedback/src/screenshot/components/ScreenshotInput.css.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
118118
.editor__tool-container {
119119
padding-top: 8px;
120120
display: flex;
121-
justify-content: space-between;
121+
justify-content: center;
122122
}
123123
.editor__tool-bar {
124124
display: flex;
@@ -147,7 +147,7 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
147147
.editor__rect {
148148
position: absolute;
149149
}
150-
.editor__rect button{
150+
.editor__rect button {
151151
opacity: 0;
152152
position: absolute;
153153
top: -12px;
@@ -158,7 +158,7 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
158158
border: none;
159159
background: none;
160160
}
161-
.editor__rect:hover button{
161+
.editor__rect:hover button {
162162
opacity: 1;
163163
}
164164
`;

packages/feedback/src/screenshot/components/Toolbarv2.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ export default function ToolbarFactoryv2({
1717
}): VNode {
1818
return (
1919
<div class="editor__tool-container">
20-
<div />
2120
<div class="editor__tool-bar">
2221
<button
2322
type="button"
2423
class={`editor__tool ${action === 'highlight' ? 'editor__tool--active' : ''}`}
2524
onClick={() => {
26-
if (action === 'highlight') {
27-
setAction('');
28-
} else {
29-
setAction('highlight');
30-
}
25+
setAction(action === 'highlight' ? '' : 'highlight');
3126
}}
3227
>
3328
Highlight
@@ -36,17 +31,12 @@ export default function ToolbarFactoryv2({
3631
type="button"
3732
class={`editor__tool ${action === 'hide' ? 'editor__tool--active' : ''}`}
3833
onClick={() => {
39-
if (action === 'hide') {
40-
setAction('');
41-
} else {
42-
setAction('hide');
43-
}
34+
setAction(action === 'hide' ? '' : 'hide');
4435
}}
4536
>
4637
Hide
4738
</button>
4839
</div>
49-
<div />
5040
</div>
5141
);
5242
};

0 commit comments

Comments
 (0)