Skip to content

Commit bc069ad

Browse files
committed
PR comments
1 parent b7d3361 commit bc069ad

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/* eslint-disable max-lines */
1+
import type { FeedbackInternalOptions } from '@sentry/core';
22
import type { VNode, h as hType } from 'preact';
33
import type * as Hooks from 'preact/hooks';
44
import { DOCUMENT, WINDOW } from '../../constants';
5-
import type { FeedbackInternalOptions } from '@sentry/core';
65
import CropCornerFactory from './CropCorner';
76

87
const CROP_BUTTON_SIZE = 30;
@@ -31,7 +30,7 @@ const constructRect = (box: Box): Rect => ({
3130
height: Math.abs(box.startY - box.endY),
3231
});
3332

34-
const getContainedSize = (img: HTMLCanvasElement): Box => {
33+
const getContainedSize = (img: HTMLCanvasElement): Rect => {
3534
const imgClientHeight = img.clientHeight;
3635
const imgClientWidth = img.clientWidth;
3736
const ratio = img.width / img.height;
@@ -43,7 +42,7 @@ const getContainedSize = (img: HTMLCanvasElement): Box => {
4342
}
4443
const x = (imgClientWidth - width) / 2;
4544
const y = (imgClientHeight - height) / 2;
46-
return { startX: x, startY: y, endX: width + x, endY: height + y };
45+
return { x: x, y: y, width: width, height: height };
4746
};
4847

4948
interface FactoryParams {
@@ -53,7 +52,7 @@ interface FactoryParams {
5352
}
5453

5554
export default function CropFactory({
56-
h, // eslint-disable-line @typescript-eslint/no-unused-vars
55+
h,
5756
hooks,
5857
options,
5958
}: FactoryParams): (props: {
@@ -99,7 +98,7 @@ export default function CropFactory({
9998
return;
10099
}
101100

102-
const imageDimensions = constructRect(getContainedSize(imageBuffer));
101+
const imageDimensions = getContainedSize(imageBuffer);
103102
const croppingBox = constructRect(croppingRect);
104103
ctx.clearRect(0, 0, imageDimensions.width, imageDimensions.height);
105104

@@ -124,7 +123,9 @@ export default function CropFactory({
124123
// Resizing logic
125124
const makeHandleMouseMove = hooks.useCallback((corner: string) => {
126125
return (e: MouseEvent) => {
127-
if (!croppingRef.current) return;
126+
if (!croppingRef.current) {
127+
return;
128+
}
128129

129130
const cropCanvas = croppingRef.current;
130131
const cropBoundingRect = cropCanvas.getBoundingClientRect();
@@ -166,13 +167,17 @@ export default function CropFactory({
166167

167168
// Dragging logic
168169
const onDragStart = (e: MouseEvent): void => {
169-
if (isResizing) return;
170+
if (isResizing) {
171+
return;
172+
}
170173

171174
initialPositionRef.current = { initialX: e.clientX, initialY: e.clientY };
172175

173176
const handleMouseMove = (moveEvent: MouseEvent): void => {
174177
const cropCanvas = croppingRef.current;
175-
if (!cropCanvas) return;
178+
if (!cropCanvas) {
179+
return;
180+
}
176181

177182
const deltaX = moveEvent.clientX - initialPositionRef.current.initialX;
178183
const deltaY = moveEvent.clientY - initialPositionRef.current.initialY;
@@ -222,7 +227,7 @@ export default function CropFactory({
222227

223228
function applyCrop(): void {
224229
const cutoutCanvas = DOCUMENT.createElement('canvas');
225-
const imageBox = constructRect(getContainedSize(imageBuffer));
230+
const imageBox = getContainedSize(imageBuffer);
226231
const croppingBox = constructRect(croppingRect);
227232
cutoutCanvas.width = croppingBox.width * DPI;
228233
cutoutCanvas.height = croppingBox.height * DPI;
@@ -269,25 +274,25 @@ export default function CropFactory({
269274
top={croppingRect.startY - CROP_BUTTON_BORDER}
270275
onGrabButton={onGrabButton}
271276
corner="top-left"
272-
></CropCorner>
277+
/>
273278
<CropCorner
274279
left={croppingRect.endX - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER}
275280
top={croppingRect.startY - CROP_BUTTON_BORDER}
276281
onGrabButton={onGrabButton}
277282
corner="top-right"
278-
></CropCorner>
283+
/>
279284
<CropCorner
280285
left={croppingRect.startX - CROP_BUTTON_BORDER}
281286
top={croppingRect.endY - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER}
282287
onGrabButton={onGrabButton}
283288
corner="bottom-left"
284-
></CropCorner>
289+
/>
285290
<CropCorner
286291
left={croppingRect.endX - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER}
287292
top={croppingRect.endY - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER}
288293
onGrabButton={onGrabButton}
289294
corner="bottom-right"
290-
></CropCorner>
295+
/>
291296
</div>
292297
)}
293298
{action === 'crop' && (

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
/* eslint-disable max-lines */
21
import type { FeedbackInternalOptions, FeedbackModalIntegration } from '@sentry/core';
32
import type { ComponentType, VNode, h as hType } from 'preact';
43
// biome-ignore lint/nursery/noUnusedImports: reason
54
import { h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-vars
65
import type * as Hooks from 'preact/hooks';
76
import { WINDOW } from '../../constants';
8-
import { createScreenshotInputStyles } from './ScreenshotInput.css';
9-
import { useTakeScreenshotFactory } from './useTakeScreenshot';
10-
import ToolbarFactory from './Toolbar';
117
import AnnotationsFactory from './Annotations';
128
import CropFactory from './Crop';
9+
import { createScreenshotInputStyles } from './ScreenshotInput.css';
10+
import ToolbarFactory from './Toolbar';
11+
import { useTakeScreenshotFactory } from './useTakeScreenshot';
1312

1413
const DPI = WINDOW.devicePixelRatio;
1514

@@ -39,16 +38,7 @@ interface Rect {
3938
width: number;
4039
}
4140

42-
const constructRect = (box: Box): Rect => {
43-
return {
44-
x: Math.min(box.startX, box.endX),
45-
y: Math.min(box.startY, box.endY),
46-
width: Math.abs(box.startX - box.endX),
47-
height: Math.abs(box.startY - box.endY),
48-
};
49-
};
50-
51-
const getContainedSize = (img: HTMLCanvasElement): Box => {
41+
const getContainedSize = (img: HTMLCanvasElement): Rect => {
5242
const imgClientHeight = img.clientHeight;
5343
const imgClientWidth = img.clientWidth;
5444
const ratio = img.width / img.height;
@@ -60,7 +50,7 @@ const getContainedSize = (img: HTMLCanvasElement): Box => {
6050
}
6151
const x = (imgClientWidth - width) / 2;
6252
const y = (imgClientHeight - height) / 2;
63-
return { startX: x, startY: y, endX: width + x, endY: height + y };
53+
return { x: x, y: y, width: width, height: height };
6454
};
6555

6656
export function ScreenshotEditorFactory({
@@ -115,7 +105,7 @@ export function ScreenshotEditorFactory({
115105
}
116106

117107
function resize(): void {
118-
const imageDimensions = constructRect(getContainedSize(imageBuffer));
108+
const imageDimensions = getContainedSize(imageBuffer);
119109

120110
resizeCanvas(croppingRef, imageDimensions);
121111
resizeCanvas(annotatingRef, imageDimensions);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { VNode, h as hType } from 'preact';
22
import type * as Hooks from 'preact/hooks';
3-
import PenIconFactory from './PenIcon';
43
import CropIconFactory from './CropIcon';
4+
import PenIconFactory from './PenIcon';
55

66
interface FactoryParams {
77
h: typeof hType;

0 commit comments

Comments
 (0)