Skip to content

Commit 1525c80

Browse files
committed
fix: set and remember city selection
1 parent 1de6521 commit 1525c80

File tree

2 files changed

+54
-39
lines changed

2 files changed

+54
-39
lines changed
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
import { Flex, Spinner } from "@artsy/palette-mobile"
21
import { MapRenderer } from "app/Scenes/Map/MapRenderer"
32
import { cityNearLocation } from "app/Scenes/Map/helpers/cityNearLocation"
43
import { GlobalStore } from "app/store/GlobalStore"
4+
import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag"
55
import { useLocation } from "app/utils/hooks/useLocation"
6-
import { useEffect } from "react"
7-
import cities from "../../../../data/cityDataSortedByDisplayPreference.json"
6+
import expandedCities from "../../../../data/cityDataSortedByDisplayPreference-expanded.json"
7+
import originalCities from "../../../../data/cityDataSortedByDisplayPreference.json"
88

99
export const CityGuide: React.FC = () => {
10+
const enabledExpandedList = useFeatureFlag("AREnableExpandedCityGuide")
11+
const cities = enabledExpandedList ? expandedCities : originalCities
12+
1013
const previouslySelectedCitySlug = GlobalStore.useAppState(
1114
(state) => state.userPrefs.previouslySelectedCitySlug
1215
)
13-
const { setPreviouslySelectedCitySlug } = GlobalStore.actions.userPrefs
1416

15-
const { location, isLoading } = useLocation()
17+
const { location } = useLocation()
18+
19+
let initialCitySlug = "new-york-ny-usa"
1620

17-
useEffect(() => {
18-
if (location && cityNearLocation(cities, location)) {
19-
setPreviouslySelectedCitySlug(cityNearLocation(cities, location)?.slug ?? "")
21+
if (location) {
22+
const nearest = cityNearLocation(cities, location)
23+
if (nearest) {
24+
initialCitySlug = nearest.slug
2025
}
21-
}, [location])
26+
}
2227

23-
if (isLoading && !previouslySelectedCitySlug) {
24-
return (
25-
<Flex flex={1} justifyContent="center" alignItems="center">
26-
<Spinner />
27-
</Flex>
28-
)
28+
if (previouslySelectedCitySlug) {
29+
initialCitySlug = previouslySelectedCitySlug
2930
}
3031

31-
return <MapRenderer citySlug={previouslySelectedCitySlug ?? "new-york-ny-usa"} />
32+
return <MapRenderer citySlug={initialCitySlug} />
3233
}

src/app/Scenes/Map/GlobalMap.tsx

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CityData, CityPicker } from "app/Scenes/City/CityPicker"
88
import { cityTabs } from "app/Scenes/City/cityTabs"
99
import { SelectedPin } from "app/Scenes/Map/Components/SelectedPin"
1010
import { MAX_GRAPHQL_INT } from "app/Scenes/Map/MapRenderer"
11+
import { GlobalStore } from "app/store/GlobalStore"
1112
import {
1213
convertCityToGeoJSON,
1314
fairToGeoCityFairs,
@@ -101,6 +102,28 @@ export const GlobalMap: React.FC<Props> = (props) => {
101102
const navigation = useNavigation()
102103

103104
useEffect(() => {
105+
const onPressCitySwitcherButton = () => {
106+
if (!showCityPicker) {
107+
// Show the city picker
108+
setShowCityPicker(true)
109+
setActiveShows([])
110+
setActivePin(null)
111+
} else {
112+
// Hide the city picker
113+
setShowCityPicker(false)
114+
}
115+
}
116+
117+
const onPressUserPositionButton = () => {
118+
// @ts-expect-error STRICTNESS_MIGRATION --- 🚨 Unsafe legacy code 🚨 Please delete this and fix any type errors if you have time 🙏
119+
const { lat, lng } = userLocation
120+
cameraRef.current?.setCamera({
121+
centerCoordinate: [lng, lat],
122+
zoomLevel: DefaultZoomLevel,
123+
animationDuration: 500,
124+
})
125+
}
126+
104127
navigation.setOptions({
105128
headerRight: () => {
106129
return (
@@ -135,7 +158,16 @@ export const GlobalMap: React.FC<Props> = (props) => {
135158
)
136159
},
137160
})
138-
}, [navigation, viewer, userLocation, showCityPicker, activePin])
161+
}, [
162+
navigation,
163+
viewer,
164+
userLocation,
165+
showCityPicker,
166+
activePin,
167+
hideButtons,
168+
safeAreaInsets.top,
169+
currentLocation,
170+
])
139171

140172
useEffect(() => {
141173
updateShowIdMap()
@@ -342,27 +374,7 @@ export const GlobalMap: React.FC<Props> = (props) => {
342374
}
343375
}
344376

345-
const onPressCitySwitcherButton = () => {
346-
if (!showCityPicker) {
347-
// Show the city picker
348-
setShowCityPicker(true)
349-
setActiveShows([])
350-
setActivePin(null)
351-
} else {
352-
// Hide the city picker
353-
setShowCityPicker(false)
354-
}
355-
}
356-
357-
const onPressUserPositionButton = () => {
358-
// @ts-expect-error STRICTNESS_MIGRATION --- 🚨 Unsafe legacy code 🚨 Please delete this and fix any type errors if you have time 🙏
359-
const { lat, lng } = userLocation
360-
cameraRef.current?.setCamera({
361-
centerCoordinate: [lng, lat],
362-
zoomLevel: DefaultZoomLevel,
363-
animationDuration: 500,
364-
})
365-
}
377+
const { setPreviouslySelectedCitySlug } = GlobalStore.actions.userPrefs
366378

367379
const currentFeatureCollection = (): FilterData => {
368380
const filterID = cityTabs[activeIndex].id
@@ -483,6 +495,8 @@ export const GlobalMap: React.FC<Props> = (props) => {
483495

484496
const onSelectCity = (newCity: CityData) => {
485497
setShowCityPicker(false)
498+
console.warn("setPreviouslySelectedCitySlug", newCity.slug)
499+
setPreviouslySelectedCitySlug(newCity.slug)
486500
refetch({ citySlug: newCity.slug, maxInt: MAX_GRAPHQL_INT })
487501
}
488502

@@ -518,7 +532,7 @@ export const GlobalMap: React.FC<Props> = (props) => {
518532
>
519533
<MapboxGL.Camera
520534
ref={cameraRef}
521-
animationMode="flyTo"
535+
animationMode="moveTo"
522536
zoomLevel={DefaultZoomLevel}
523537
minZoomLevel={MinZoomLevel}
524538
maxZoomLevel={MaxZoomLevel}

0 commit comments

Comments
 (0)