Skip to content

Commit

Permalink
refactor: clear areaId if nothing under click
Browse files Browse the repository at this point in the history
  • Loading branch information
clintonlunn committed Nov 27, 2024
1 parent 2c994cd commit 09ff2b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/app/(maps)/components/FullScreenMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ export const FullScreenMap: React.FC = () => {

const handleMapClick = useCallback(
(e: MapLayerMouseEvent) => {
const areaId = e.features?.[0]?.properties?.id
if (areaId === '') {
return
}

const areaId = e.features?.[0]?.properties?.id ?? null
const { camera } = urlParams.fromUrl()
const url = urlParams.toUrl({ camera: camera ?? null, areaId })
router.replace(url, { scroll: false })
Expand Down
2 changes: 1 addition & 1 deletion src/components/maps/GlobalMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ export const GlobalMap: React.FC<GlobalMapProps> = ({
const onClick = (event: MapLayerMouseEvent): void => {
if (mapInstance === null) return
const feature = event?.features?.[0]
handleOnClick?.(event)
if (feature === undefined) {
setClickInfo(null)
} else {
const { layer, geometry, properties } = feature
handleOnClick?.(event)
setClickInfo(prev => {
setActiveFeatureVisual(prev, { selected: false, hover: false })
const activeFeature = tileToFeature(layer.id, event.point, geometry, properties as TileProps, mapInstance)
Expand Down
14 changes: 5 additions & 9 deletions src/js/hooks/useUrlParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ const useUrlParams = (): UseUrlParamsReturn => {
}

const baseUrl = `${pathname}?`
const cameraParam = (camera != null) ? `camera=${cameraInfoToQuery(camera)}` : ''
const cameraParam = camera != null ? `camera=${cameraInfoToQuery(camera)}` : ''
const otherParams = params.toString()

if (cameraParam != null && otherParams != null) {
return `${baseUrl}${cameraParam}&${otherParams}`
} else if (cameraParam != null) {
return `${baseUrl}${cameraParam}`
} else if (otherParams != null) {
return `${baseUrl}${otherParams}`
}
const query = [cameraParam, otherParams]
.filter(param => param !== '') // Remove empty params
.join('&') // Join non-empty params with `&`

return pathname
return query !== '' ? `${baseUrl}${query}` : pathname // Return base URL if query is empty
}

const fromUrl = (): UrlProps => {
Expand Down

0 comments on commit 09ff2b9

Please sign in to comment.