Skip to content

Commit

Permalink
fix(geoSearch): hasMapMovedSinceLastRefine (#6470)
Browse files Browse the repository at this point in the history
The property that is exposed is called `hasMapMovedSinceLastRefine`, no longer `hasMapMoveSinceLastRefine`

BREAKING CHANGE: replace `hasMapMoveSinceLastRefine` in your code base with `hasMapMovedSinceLastRefine`
  • Loading branch information
Haroenv authored Dec 12, 2024
1 parent 9e85cf1 commit c8f143c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
toggleRefineOnMapMove: expect.any(Function),
isRefineOnMapMove: expect.any(Function),
setMapMoveSinceLastRefine: expect.any(Function),
hasMapMoveSinceLastRefine: expect.any(Function),
hasMapMovedSinceLastRefine: expect.any(Function),
widgetParams: {},
instantSearchInstance,
},
true
);

expect(lastRenderArgs(render).isRefineOnMapMove()).toBe(true);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);

widget.render!(
Expand Down Expand Up @@ -222,7 +222,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(lastRenderArgs(render).isRefineOnMapMove()).toBe(true);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
});

Expand Down Expand Up @@ -496,13 +496,13 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(4);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

helper.setQueryParameter('aroundLatLng', '14,16');
Expand All @@ -515,7 +515,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(5);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);
});

Expand Down Expand Up @@ -574,13 +574,13 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(4);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

helper.setQueryParameter('aroundLatLng', '10,12');
Expand All @@ -593,7 +593,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(5);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);
});

Expand Down Expand Up @@ -653,13 +653,13 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(4);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

helper.setQueryParameter('insideBoundingBox', undefined);
Expand All @@ -672,7 +672,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(5);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
});

Expand Down Expand Up @@ -732,13 +732,13 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(4);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

// @ts-ignore
Expand All @@ -752,7 +752,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(5);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);
});

Expand Down Expand Up @@ -938,7 +938,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(1);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
expect(helper.state.insideBoundingBox).toBe(undefined);
expect(helper.search).not.toHaveBeenCalled();
Expand All @@ -953,7 +953,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(2);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);
expect(helper.state.insideBoundingBox).toEqual('12,10,40,42');
expect(helper.search).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -999,7 +999,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(2);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
expect(helper.state.insideBoundingBox).toBe(undefined);
expect(helper.search).not.toHaveBeenCalled();
Expand All @@ -1014,7 +1014,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);
expect(helper.state.insideBoundingBox).toEqual('12,10,40,42');
expect(helper.search).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -1055,7 +1055,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(1);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
expect(helper.state.insideBoundingBox).toBe(undefined);
expect(helper.search).not.toHaveBeenCalled();
Expand All @@ -1070,7 +1070,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(2);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);
expect(helper.state.insideBoundingBox).toEqual('12,10,40,42');
expect(helper.search).toHaveBeenCalledTimes(1);
Expand All @@ -1085,7 +1085,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
expect(helper.state.insideBoundingBox).toBe(undefined);
expect(helper.search).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -1131,7 +1131,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(2);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
expect(helper.state.insideBoundingBox).toBe(undefined);
expect(helper.search).not.toHaveBeenCalled();
Expand All @@ -1146,7 +1146,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);
expect(helper.state.insideBoundingBox).toEqual('12,10,40,42');
expect(helper.search).toHaveBeenCalledTimes(1);
Expand All @@ -1161,7 +1161,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(4);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(false);
expect(helper.state.insideBoundingBox).toBe(undefined);
expect(helper.search).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -1262,12 +1262,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
widget.init!(createInitOptions());

expect(render).toHaveBeenCalledTimes(1);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(1);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);

widget.render!(
createRenderOptions({
Expand All @@ -1280,7 +1280,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(2);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(firstRenderArgs(render).setMapMoveSinceLastRefine).toBe(
lastRenderArgs(render).setMapMoveSinceLastRefine
);
Expand Down Expand Up @@ -1318,12 +1318,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(2);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(firstRenderArgs(render).setMapMoveSinceLastRefine).toBe(
lastRenderArgs(render).setMapMoveSinceLastRefine
);
Expand Down Expand Up @@ -1361,17 +1361,17 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
);

expect(render).toHaveBeenCalledTimes(2);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(false);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(false);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);

lastRenderArgs(render).setMapMoveSinceLastRefine();

expect(render).toHaveBeenCalledTimes(3);
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).hasMapMovedSinceLastRefine()).toBe(true);
expect(firstRenderArgs(render).setMapMoveSinceLastRefine).toBe(
lastRenderArgs(render).setMapMoveSinceLastRefine
);
Expand Down Expand Up @@ -1593,7 +1593,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
currentRefinement: undefined,
items: [],
clearMapRefinement: expect.any(Function),
hasMapMoveSinceLastRefine: expect.any(Function),
hasMapMovedSinceLastRefine: expect.any(Function),
isRefineOnMapMove: expect.any(Function),
isRefinedWithMap: expect.any(Function),
refine: expect.any(Function),
Expand Down Expand Up @@ -1630,7 +1630,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
items: [],
refine: expect.any(Function),
clearMapRefinement: expect.any(Function),
hasMapMoveSinceLastRefine: expect.any(Function),
hasMapMovedSinceLastRefine: expect.any(Function),
isRefineOnMapMove: expect.any(Function),
isRefinedWithMap: expect.any(Function),
setMapMoveSinceLastRefine: expect.any(Function),
Expand Down Expand Up @@ -1658,7 +1658,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
currentRefinement: undefined,
items: [],
clearMapRefinement: expect.any(Function),
hasMapMoveSinceLastRefine: expect.any(Function),
hasMapMovedSinceLastRefine: expect.any(Function),
isRefineOnMapMove: expect.any(Function),
isRefinedWithMap: expect.any(Function),
refine: expect.any(Function),
Expand Down
19 changes: 9 additions & 10 deletions packages/instantsearch-core/src/connectors/connectGeoSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type GeoSearchRenderState<THit extends NonNullable<object> = BaseHit> = {
/**
* Return true if the map has move since the last refinement.
*/
hasMapMoveSinceLastRefine: () => boolean;
hasMapMovedSinceLastRefine: () => boolean;
/**
* Return true if the current refinement is set with the map bounds.
*/
Expand Down Expand Up @@ -179,8 +179,7 @@ export const connectGeoSearch = function connectGeoSearch<

const widgetState = {
isRefineOnMapMove: enableRefineOnMapMove,
// @MAJOR hasMapMoveSinceLastRefine -> hasMapMovedSinceLastRefine
hasMapMoveSinceLastRefine: false,
hasMapMovedSinceLastRefine: false,
lastRefinePosition: '',
lastRefineBoundingBox: '',
internalToggleRefineOnMapMove: noop,
Expand All @@ -207,7 +206,7 @@ export const connectGeoSearch = function connectGeoSearch<
)
.search();

widgetState.hasMapMoveSinceLastRefine = false;
widgetState.hasMapMovedSinceLastRefine = false;
widgetState.lastRefineBoundingBox = boundingBox;
};

Expand Down Expand Up @@ -246,17 +245,17 @@ export const connectGeoSearch = function connectGeoSearch<
) =>
() => {
const shouldTriggerRender =
widgetState.hasMapMoveSinceLastRefine !== true;
widgetState.hasMapMovedSinceLastRefine !== true;

widgetState.hasMapMoveSinceLastRefine = true;
widgetState.hasMapMovedSinceLastRefine = true;

if (shouldTriggerRender) {
render(renderOptions);
}
};

const hasMapMoveSinceLastRefine = () =>
widgetState.hasMapMoveSinceLastRefine;
const hasMapMovedSinceLastRefine = () =>
widgetState.hasMapMovedSinceLastRefine;

let sendEvent: SendEventForHits;

Expand Down Expand Up @@ -307,7 +306,7 @@ export const connectGeoSearch = function connectGeoSearch<
positionChangedSinceLastRefine ||
boundingBoxChangedSinceLastRefine
) {
widgetState.hasMapMoveSinceLastRefine = false;
widgetState.hasMapMovedSinceLastRefine = false;
}

widgetState.lastRefinePosition = state.aroundLatLng || '';
Expand Down Expand Up @@ -369,7 +368,7 @@ export const connectGeoSearch = function connectGeoSearch<
toggleRefineOnMapMove,
isRefineOnMapMove,
setMapMoveSinceLastRefine,
hasMapMoveSinceLastRefine,
hasMapMovedSinceLastRefine,
widgetParams,
};
},
Expand Down
Loading

0 comments on commit c8f143c

Please sign in to comment.