-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from coldsurfers/release/billets-app-v1.6.0
release(billets-app): 🚀 v1.6.0
- Loading branch information
Showing
115 changed files
with
1,825 additions
and
901 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './use-map-points' | ||
export * from './use-map-region-with-zoom-level' | ||
export * from './use-map-region-with-zoom-level.types' | ||
export * from './use-super-cluster' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { $api } from '@/lib/api/openapi-client' | ||
import uniqBy from 'lodash.uniqby' | ||
import { useEffect, useState } from 'react' | ||
import { z } from 'zod' | ||
import { mapPointSchema } from '../map.types' | ||
import { MapRegionWithZoomLevel } from './use-map-region-with-zoom-level.types' | ||
|
||
export const useMapPoints = ({ mapRegionWithZoomLevel }: { mapRegionWithZoomLevel: MapRegionWithZoomLevel }) => { | ||
const { data: locationConcerts, isLoading: isLoadingLocationConcerts } = $api.useQuery( | ||
'get', | ||
'/v1/location/concert', | ||
{ | ||
params: { | ||
query: { | ||
latitude: `${mapRegionWithZoomLevel.latitude}`, | ||
latitudeDelta: `${mapRegionWithZoomLevel.latitudeDelta}`, | ||
longitude: `${mapRegionWithZoomLevel.longitude}`, | ||
longitudeDelta: `${mapRegionWithZoomLevel.longitudeDelta}`, | ||
zoomLevel: `${mapRegionWithZoomLevel.zoomLevel}`, | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
const [points, setPoints] = useState<z.infer<typeof mapPointSchema>[]>([]) | ||
const [visiblePoints, setVisiblePoints] = useState<z.infer<typeof mapPointSchema>[]>([]) | ||
|
||
useEffect(() => { | ||
if (!locationConcerts) { | ||
return | ||
} | ||
const newPoints = locationConcerts.map((locationConcert, index) => { | ||
return { | ||
id: index, | ||
originalId: locationConcert.id, | ||
type: 'Feature', | ||
properties: { cluster_id: index }, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [locationConcert.longitude, locationConcert.latitude], | ||
}, | ||
} satisfies z.infer<typeof mapPointSchema> | ||
}) | ||
setVisiblePoints(newPoints) | ||
setPoints((prevPoints) => { | ||
const validation = mapPointSchema.array().safeParse(newPoints) | ||
if (validation.error) { | ||
console.error(validation.error) | ||
return prevPoints | ||
} | ||
|
||
const newValue = uniqBy([...prevPoints, ...validation.data], 'originalId') | ||
return newValue | ||
}) | ||
}, [locationConcerts]) | ||
|
||
return { | ||
locationConcerts, | ||
isLoadingLocationConcerts, | ||
points, | ||
setPoints, | ||
visiblePoints, | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
apps/billets-app/src/features/map/hooks/use-map-region-with-zoom-level.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useState } from 'react' | ||
import { getZoomLevel } from '../utils' | ||
import { MapRegionWithZoomLevel, UseMapRegionWithZoomLevelParams } from './use-map-region-with-zoom-level.types' | ||
|
||
export const useMapRegionWithZoomLevel = ({ latitude, longitude }: UseMapRegionWithZoomLevelParams) => { | ||
const [mapRegionWithZoomLevel, setMapRegionWithZoomLevel] = useState<MapRegionWithZoomLevel>({ | ||
latitude: latitude, | ||
longitude: longitude, | ||
latitudeDelta: 0.0922, | ||
longitudeDelta: 0.0421, | ||
zoomLevel: getZoomLevel(0.0922), | ||
}) | ||
|
||
return { | ||
mapRegionWithZoomLevel, | ||
setMapRegionWithZoomLevel, | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/billets-app/src/features/map/hooks/use-map-region-with-zoom-level.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Region } from 'react-native-maps' | ||
|
||
export type MapRegionWithZoomLevel = Region & { | ||
zoomLevel: number | ||
} | ||
|
||
export type UseMapRegionWithZoomLevelParams = { | ||
latitude: number | ||
longitude: number | ||
} |
52 changes: 52 additions & 0 deletions
52
apps/billets-app/src/features/map/hooks/use-super-cluster.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useEffect, useState } from 'react' | ||
import Supercluster from 'supercluster' | ||
import { z } from 'zod' | ||
import { mapPointSchema } from '../map.types' | ||
import { getZoomLevel } from '../utils' | ||
import { MapRegionWithZoomLevel } from './use-map-region-with-zoom-level.types' | ||
|
||
export const useSuperCluster = ({ | ||
mapRegionWithZoomLevel, | ||
points, | ||
}: { | ||
mapRegionWithZoomLevel: MapRegionWithZoomLevel | ||
points: z.infer<typeof mapPointSchema>[] | ||
}) => { | ||
const [supercluster] = useState( | ||
() => | ||
new Supercluster({ | ||
radius: 40, | ||
maxZoom: 16, | ||
minZoom: 1, | ||
}), | ||
) | ||
|
||
const [clusters, setClusters] = useState<z.infer<typeof mapPointSchema>[]>([]) | ||
|
||
useEffect(() => { | ||
const region = mapRegionWithZoomLevel | ||
const zoomLevel = getZoomLevel(region.latitudeDelta) | ||
|
||
const bbox = [ | ||
region.longitude - region.longitudeDelta, | ||
region.latitude - region.latitudeDelta, | ||
region.longitude + region.longitudeDelta, | ||
region.latitude + region.latitudeDelta, | ||
] as [number, number, number, number] | ||
|
||
supercluster.load(points) | ||
const clusters = supercluster.getClusters(bbox, zoomLevel) | ||
const clustersValidation = mapPointSchema.array().safeParse(clusters) | ||
|
||
if (clustersValidation.success) { | ||
setClusters(clustersValidation.data) | ||
} else { | ||
console.error(clustersValidation.error) | ||
} | ||
}, [mapRegionWithZoomLevel, points, supercluster]) | ||
|
||
return { | ||
clusters, | ||
supercluster, | ||
} | ||
} |
Oops, something went wrong.