diff --git a/src/app/Scenes/Map/CityGuideMap.tsx b/src/app/Scenes/Map/CityGuideMap.tsx index f9a5f65a42f..77bafedd6fd 100644 --- a/src/app/Scenes/Map/CityGuideMap.tsx +++ b/src/app/Scenes/Map/CityGuideMap.tsx @@ -1,11 +1,12 @@ -import { Flex, useTheme } from "@artsy/palette-mobile" -import MapboxGL from "@react-native-mapbox-gl/maps" -import { CityGuideMapQuery } from "__generated__/CityGuideMapQuery.graphql" +import { Flex, Text, useTheme, Image } from "@artsy/palette-mobile" +import MapboxGL, { OnPressEvent } from "@react-native-mapbox-gl/maps" +import { CityGuideMapQuery, CityGuideMapQuery$data } from "__generated__/CityGuideMapQuery.graphql" import { ArtsyMapStyleURL } from "app/Scenes/Map/GlobalMap" import { FilterData } from "app/Scenes/Map/types" +import { navigate } from "app/system/navigation/navigate" import { convertCityToGeoJSON } from "app/utils/convertCityToGeoJSON" -import React, { useEffect, useRef } from "react" -import { Dimensions } from "react-native" +import React, { useEffect, useRef, useState } from "react" +import { Dimensions, TouchableWithoutFeedback } from "react-native" import Config from "react-native-config" import { graphql, useLazyLoadQuery } from "react-relay" import Supercluster from "supercluster" @@ -24,7 +25,8 @@ export const CityGuideMap: React.FC = ({ citySlug }) => { const mapRef = useRef(null) const cameraRef = useRef(null) - const [pinsToRender, setPinsToRender] = React.useState(undefined) + const [pinsToRender, setPinsToRender] = useState(undefined) + const [selectedShow, setSelectedShow] = useState(null) useEffect(() => { if (!data) { @@ -66,63 +68,110 @@ export const CityGuideMap: React.FC = ({ citySlug }) => { const { color } = useTheme() + const handlePress = async (event: OnPressEvent) => { + if (!event.features.length) { + return + } + + const slug = event.features[0].properties?.slug + const cluster = event.features[0].properties?.cluster + + /** A pin was tapped (instead of a cluster) */ + if (!cluster && slug && data?.city?.shows?.edges) { + const show: Show | null | undefined = data.city.shows.edges.find( + (edge) => edge?.node?.slug === slug + )?.node + + if (!show) { + return + } + + if (show.location?.coordinates?.lat && show.location?.coordinates?.lng) { + cameraRef.current?.flyTo([show.location.coordinates.lng, show.location.coordinates.lat]) + } + + setSelectedShow(show) + } + } + return ( - - - - - {!!pinsToRender && ( - - - - - - )} - - + + + + {!!pinsToRender && ( + + + + + + )} + + {!!selectedShow && ( + + navigate(`/show/${selectedShow.slug}`)}> + + {!!selectedShow.coverImage?.url && ( + + )} + + + {selectedShow.partner?.name} + + + {selectedShow.name} + + + Ongoing + + + + + + )} ) } @@ -185,3 +234,11 @@ const NEW_YORK_COORDINATES = { lat: 40.713, lng: -74.006 } const DEFAULT_ZOOM_LEVEL = 11 const MIN_ZOOM_LEVEL = 9 const MAX_ZOOM_LEVEL = 17.5 + +type Show = NonNullable< + NonNullable< + NonNullable< + NonNullable["city"]>["shows"]>["edges"] + >[0] + >["node"] +>