Skip to content

Commit b406ea3

Browse files
committed
don't add plant/point/weed after orbit drag release
1 parent 49df48f commit b406ea3

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

frontend/three_d_garden/bed/objects/__tests__/pointer_objects_test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { render } from "@testing-library/react";
1717
import { INITIAL } from "../../../config";
1818
import { fakeAddPlantProps } from "../../../../__test_support__/fake_props";
19+
import { fakeDrawnPoint } from "../../../../__test_support__/fake_designer_state";
1920
import { clone } from "lodash";
2021
import { Path } from "../../../../internal_urls";
2122
import { Vector3 } from "three";
@@ -130,6 +131,42 @@ describe("soilClick()", () => {
130131
gardenCoords: { x: 1360, y: 660 },
131132
}));
132133
});
134+
135+
it("doesn't create a plant after a drag", () => {
136+
location.pathname = Path.mock(Path.cropSearch("mint"));
137+
mockIsMobile = false;
138+
const p = fakeProps();
139+
const e = {
140+
stopPropagation: jest.fn(),
141+
point: { x: 1, y: 2 },
142+
delta: 3,
143+
} as unknown as ThreeEvent<MouseEvent>;
144+
soilClick(p)(e);
145+
expect(e.stopPropagation).toHaveBeenCalled();
146+
expect(dropPlantSpy).not.toHaveBeenCalled();
147+
});
148+
149+
it.each([
150+
["point", Path.points("add")],
151+
["weed", Path.weeds("add")],
152+
])("doesn't set %s location after a drag", (_label, path) => {
153+
location.pathname = Path.mock(path);
154+
mockIsMobile = false;
155+
const p = fakeProps();
156+
const point = fakeDrawnPoint();
157+
point.cx = undefined;
158+
point.cy = undefined;
159+
point.r = 0;
160+
p.addPlantProps.designer.drawnPoint = point;
161+
const e = {
162+
stopPropagation: jest.fn(),
163+
point: { x: 1, y: 2 },
164+
delta: 3,
165+
} as unknown as ThreeEvent<MouseEvent>;
166+
soilClick(p)(e);
167+
expect(e.stopPropagation).toHaveBeenCalled();
168+
expect(p.addPlantProps.dispatch).not.toHaveBeenCalled();
169+
});
133170
});
134171

135172
describe("soilPointerMove()", () => {

frontend/three_d_garden/bed/objects/pointer_objects.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,14 @@ export interface SoilClickProps {
178178
getZ(x: number, y: number): number;
179179
}
180180

181+
export const MAX_SOIL_CLICK_DELTA = 2;
182+
181183
export const soilClick = (props: SoilClickProps) =>
182184
(e: ThreeEvent<MouseEvent>) => {
183185
const { config, navigate, addPlantProps, pointerPlantRef } = props;
184186
const getGardenPosition = getGardenPositionFunc(config);
185187
e.stopPropagation();
188+
if ((e.delta || 0) > MAX_SOIL_CLICK_DELTA) { return; }
186189
if (addPlantProps) {
187190
if (getMode() == Mode.clickToAdd) {
188191
dropPlant({

0 commit comments

Comments
 (0)