Skip to content

Commit

Permalink
small refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
brauliodiez committed Aug 9, 2024
1 parent cbd4007 commit a34f10f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/common/components/front-rich-components/video-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const videoPlayerShapeSizeRestrictions: ShapeSizeRestrictions = {
minHeight: 150,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 800,
defaultHeight: 600,
defaultWidth: 600,
defaultHeight: 400,
};

export const getVideoPlayerShapeSizeRestrictions = (): ShapeSizeRestrictions =>
Expand Down
2 changes: 1 addition & 1 deletion src/pods/canvas/canvas.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getLabelSizeRestrictions } from '@/common/components/front-components/l
import { getRectangleShapeSizeRestrictions } from '@/common/components/front-basic-sapes';
import { getVideoPlayerShapeSizeRestrictions } from '@/common/components/front-rich-components';

const getDefaultSizeFromShape = (shapeType: ShapeType): Size => {
export const getDefaultSizeFromShape = (shapeType: ShapeType): Size => {
switch (shapeType) {
case 'label':
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const renderRectangle = (
ref={shapeRefs.current[shape.id]}
x={shape.x}
y={shape.y}
name="shape"
width={shape.width}
height={shape.height}
draggable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const renderVideoPlayer = (
ref={shapeRefs.current[shape.id]}
x={shape.x}
y={shape.y}
name="shape"
width={shape.width}
height={shape.height}
draggable
Expand Down
6 changes: 5 additions & 1 deletion src/pods/canvas/use-monitor-shape.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from './canvas.util';
import Konva from 'konva';
import { ShapeType } from '@/core/model';
import { calculateShapeOffsetToXDropCoordinate } from './use-monitor.business';

export const useMonitorShape = (
dropRef: React.MutableRefObject<null>,
Expand All @@ -23,6 +24,7 @@ export const useMonitorShape = (
invariant(destination);

const type = source.data.type as ShapeType;

const screenPosition =
extractScreenCoordinatesFromPragmaticLocation(location);

Expand All @@ -47,7 +49,9 @@ export const useMonitorShape = (
}
);

positionX = konvaCoord.x;
positionX =
konvaCoord.x -
calculateShapeOffsetToXDropCoordinate(konvaCoord.x, type);
positionY = konvaCoord.y;
}
addNewShape(type, positionX, positionY);
Expand Down
13 changes: 13 additions & 0 deletions src/pods/canvas/use-monitor.business.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ShapeType } from '@/core/model';
import { getDefaultSizeFromShape } from './canvas.model';

// TODO: #156 Add unit tests to this funcion
export const calculateShapeOffsetToXDropCoordinate = (
cordinateX: number,
shapeType: ShapeType
): number => {
const defaultShapeSize = getDefaultSizeFromShape(shapeType);
const offset = defaultShapeSize.width / 2;

return cordinateX - offset > 0 ? offset : 0;
};

0 comments on commit a34f10f

Please sign in to comment.