-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Fix map #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Fix map #351
Changes from 7 commits
09def26
7060df9
bb76f95
5f0c362
526ff9a
9237563
5be7d7f
5408129
c361016
75f73dd
c99bec4
ebd07b7
b8b0817
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,14 +31,43 @@ export const SearchMap = ({ | |
| null | ||
| ); | ||
| const { userLocation, aroundLatLng } = useAppContext(); | ||
| const { setAroundLatLng } = useAppContextUpdater(); | ||
| const { setAroundLatLng, setAroundRadius, setBoundingBox } = | ||
| useAppContextUpdater(); | ||
|
|
||
| // Dynamically calculate search radius based on zoom level | ||
|
|
||
| function handleSearchThisAreaClick() { | ||
| const center = googleMapObject?.getCenter(); | ||
| if (center?.lat() && center?.lng()) { | ||
| setAroundLatLng(`${center.lat()}, ${center.lng()}`); | ||
| const map = googleMapObject; | ||
| if (map) { | ||
| // Get the visible bounds of the map | ||
| const bounds = map.getBounds(); | ||
| if (bounds) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question (if-minor): Out of pure curiosity, did you find that |
||
| const ne = bounds.getNorthEast(); | ||
| const sw = bounds.getSouthWest(); | ||
|
|
||
| // Format as Algolia expects: "lat1,lng1,lat2,lng2" | ||
| // Where (lat1, lng1) is the top-left (NW) corner and (lat2, lng2) is the bottom-right (SE) corner | ||
| const boundingBoxString = `${ne.lat()},${sw.lng()},${sw.lat()},${ne.lng()}`; | ||
|
|
||
| // Update the bounding box for search | ||
| setBoundingBox(boundingBoxString); | ||
|
|
||
| // Set aroundRadius to "all" to disable radius-based filtering | ||
| setAroundRadius("all"); | ||
|
|
||
| // Keep center point updated for reference (used for map centering) | ||
| const center = map.getCenter(); | ||
| if (center) { | ||
| const centerStr = `${center.lat()}, ${center.lng()}`; | ||
| setAroundLatLng(centerStr); | ||
| } | ||
|
|
||
| // Notify SearchResultsPage component to reset pagination | ||
| handleSearchMapAction(SearchMapActions.SearchThisArea); | ||
| } | ||
| } else { | ||
| handleSearchMapAction(SearchMapActions.SearchThisArea); | ||
| } | ||
| handleSearchMapAction(SearchMapActions.SearchThisArea); | ||
| } | ||
|
|
||
| const aroundLatLngToMapCenter = { | ||
|
|
@@ -127,6 +156,23 @@ export const SearchMap = ({ | |
| // SetMapObject shares the Google Map object across parent/sibling components | ||
| // so that they can adjustments to markers, coordinates, layout, etc., | ||
| setMapObject(map); | ||
|
|
||
| // Set initial bounding box when map is first loaded | ||
| const idleListener = map.addListener("idle", () => { | ||
| // Remove the listener so it only fires once | ||
| google.maps.event.removeListener(idleListener); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: Man this kind of variable access in JS (via "hoisting") always breaks my brain. What about expanding this comment so folks unfamiliar with gmaps might understand this a little better: |
||
|
|
||
| const bounds = map.getBounds(); | ||
| if (bounds) { | ||
| const ne = bounds.getNorthEast(); | ||
| const sw = bounds.getSouthWest(); | ||
| const boundingBoxString = `${ne.lat()},${sw.lng()},${sw.lat()},${ne.lng()}`; | ||
| setBoundingBox(boundingBoxString); | ||
|
|
||
| // Notify that map is initialized | ||
| handleSearchMapAction(SearchMapActions.MapInitialized); | ||
| } | ||
| }); | ||
| }} | ||
| options={createMapOptions} | ||
| > | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,32 @@ | ||
| import React, { ReactNode } from "react"; | ||
| import React from "react"; | ||
| import styles from "components/SearchAndBrowse/SearchResults/SearchResults.module.scss"; | ||
| import ClearSearchButton from "components/SearchAndBrowse/Refinements/ClearSearchButton"; | ||
| import { HITS_PER_PAGE } from "pages/SearchResultsPage/SearchResultsPage"; | ||
|
|
||
| /** | ||
| * Layout component for the header above the search results list that allows for | ||
| * flexible composition of child components. | ||
| */ | ||
| export const SearchResultsHeader = ({ children }: { children: ReactNode }) => ( | ||
| <div className={styles.searchResultsHeader}>{children}</div> | ||
| ); | ||
| export const SearchResultsHeader = ({ | ||
| currentPage, | ||
| totalResults, | ||
| }: { | ||
| currentPage: number; | ||
| totalResults: number; | ||
| }) => { | ||
| const firstResultIndex = currentPage * HITS_PER_PAGE + 1; | ||
| const lastResultIndex = Math.min( | ||
| (currentPage + 1) * HITS_PER_PAGE, | ||
| totalResults | ||
| ); | ||
| return ( | ||
| <div className={styles.searchResultsHeader}> | ||
| <h2 style={{ fontWeight: 500, fontSize: 16 }}> | ||
| Showing <span style={{ fontWeight: 700 }}>{firstResultIndex}</span> -{" "} | ||
| <span style={{ fontWeight: 700 }}>{lastResultIndex}</span> of{" "} | ||
| <span style={{ fontWeight: 700 }}>{totalResults}</span> results | ||
chadbrokaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </h2> | ||
| <ClearSearchButton /> | ||
| </div> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: 😌 Really nice comments in
handleSearchThisAreaClick()otherwise those operations are pretty opaque not behind meaningful names.