Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix: set reset x and y to just offset

httpjamesm143df10066d3
diff --git a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/CropMenu.tsx b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/CropMenu.tsx
index 8231792dd4..c98da4cbaf 100644
--- a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/CropMenu.tsx
+++ b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/CropMenu.tsx
@@ -20,6 +20,7 @@ const CropMenu = (props: IProps) => {
canvasLoading,
setCanvasLoading,
setTransformationPerformed,
+ setCurrentTab,
} = useContext(ImageEditorOverlayContext);
const [selectedRegionOfPreviewCanvas, setSelectedRegionOfPreviewCanvas] =
@@ -95,6 +96,8 @@ const CropMenu = (props: IProps) => {
const y2 = y1 + cropBoxRect.height;
cropRegionOfCanvas(canvasRef.current, x1, y1, x2, y2);
+
+ setCurrentTab('transform');
}}
label="Apply"
/>
diff --git a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
index f3bd801fbf..95e9b57193 100644
--- a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
@@ -60,9 +60,12 @@ export const ImageEditorOverlayContext = createContext(
setTransformationPerformed: Dispatch<SetStateAction<boolean>>;
setCanvasLoading: Dispatch<SetStateAction<boolean>>;
canvasLoading: boolean;
+ setCurrentTab: Dispatch<SetStateAction<OperationTab>>;
}
);
+type OperationTab = 'crop' | 'transform' | 'colours';
+
const filterDefaultValues = {
brightness: 100,
contrast: 100,
@@ -81,6 +84,11 @@ const getEditedFileName = (fileName: string) => {
// CORNER_THRESHOLD defines the threshold near the corners of the crop box in which dragging is assumed as not the intention
const CORNER_THRESHOLD = 20;
+const DEFAULT_CROPBOX_DIMENSIONS = {
+ height: 100,
+ width: 100,
+};
+
const handleStyle = {
position: 'absolute',
height: '10px',
@@ -135,9 +143,7 @@ const ImageEditorOverlay = (props: IProps) => {
const [currentRotationAngle, setCurrentRotationAngle] = useState(0);
- const [currentTab, setCurrentTab] = useState<
- 'crop' | 'transform' | 'colours'
- >('transform');
+ const [currentTab, setCurrentTab] = useState<OperationTab>('transform');
const [brightness, setBrightness] = useState(
filterDefaultValues.brightness
@@ -230,8 +236,7 @@ const ImageEditorOverlay = (props: IProps) => {
const dx = e.pageX - startX;
const dy = e.pageY - startY;
- const { offsetX, offsetY, canvasBounds, parentBounds } =
- getCanvasBoundsOffsets();
+ const { offsetX, offsetY, canvasBounds } = getCanvasBoundsOffsets();
if (isGrowing) {
setCropBox((prev) => {
@@ -284,24 +289,20 @@ const ImageEditorOverlay = (props: IProps) => {
setIsDragging(false);
};
- const moveCropBoxToTopLeft = () => {
- const { offsetX, offsetY, canvasBounds, parentBounds } =
- getCanvasBoundsOffsets();
+ const resetCropBox = () => {
+ setCropBox((prev) => {
+ const { offsetX, offsetY } = getCanvasBoundsOffsets();
- // Set the crop box position to the top-left corner of the canvas, accounting for the offset
- setCropBox((prev) => ({
- ...prev,
- x: offsetX,
- y: offsetY,
- }));
+ return {
+ ...prev,
+ x: offsetX,
+ y: offsetY,
+ height: DEFAULT_CROPBOX_DIMENSIONS.height,
+ width: DEFAULT_CROPBOX_DIMENSIONS.width,
+ };
+ });
};
- useEffect(() => {
- if (!canvasRef.current || !parentRef.current || !cropBoxRef.current)
- return;
- moveCropBoxToTopLeft();
- }, [canvasRef.current, parentRef.current, cropBoxRef.current]);
-
useEffect(() => {
if (!canvasRef.current) {
return;
@@ -394,7 +395,7 @@ const ImageEditorOverlay = (props: IProps) => {
return;
}
- moveCropBoxToTopLeft();
+ resetCropBox();
setStartX(0);
setStartY(0);
setIsDragging(false);
@@ -780,6 +781,7 @@ const ImageEditorOverlay = (props: IProps) => {
setCanvasLoading,
canvasLoading,
setTransformationPerformed,
+ setCurrentTab,
}}>
{currentTab === 'crop' && (
<CropMenu