@@ -9,21 +9,10 @@ import getAddressString from "../../../lib/getAddressString";
9
9
import getAddressStringFromA11yJSONFeature from "../../../lib/getAddressStringFromA11yJSONFeature" ;
10
10
import openButtonCaption from "../../../lib/openButtonCaption" ;
11
11
import { UAResult } from "../../../lib/userAgent" ;
12
- import { fetchJSON , generateGetPlaceInfoURL } from "../../helper " ;
12
+ import fetchJSON from "../../fetchJSON " ;
13
13
import PlaceIcon from "../../icons/actions/Place" ;
14
14
import RouteIcon from "../../icons/actions/Route" ;
15
15
16
- function useParentPlaceInfo ( parentPlaceInfoId : string ) {
17
- const appContext = React . useContext ( AppContext ) ;
18
- const baseUrl = generateGetPlaceInfoURL ( {
19
- baseUrl : appContext . baseUrl ,
20
- placeInfoId : parentPlaceInfoId ,
21
- appToken : appContext . app . tokenString ,
22
- } ) ;
23
- const { data, error } = useSWR < any > ( baseUrl , fetchJSON ) ;
24
- return { data, error } ;
25
- }
26
-
27
16
function getAddressForACProperties ( properties : AccessibilityCloudProperties ) : string | null {
28
17
if ( typeof properties . address === "string" ) return properties . address ;
29
18
if ( typeof properties . address === "object" ) {
@@ -41,14 +30,7 @@ function getAddressForACProperties(properties: AccessibilityCloudProperties): st
41
30
return null ;
42
31
}
43
32
44
- function useAddressForProperties ( properties : NodeProperties ) : string | null {
45
- if ( ( properties as any ) ?. parentPlaceInfo ) {
46
- const parentPlaceInfo = useParentPlaceInfo ( ( properties as any ) ?. parentPlaceInfo ) ;
47
- // Use parentPlaceInfo to get the address, if necessary
48
- console . log ( "data: " + parentPlaceInfo . data ) ;
49
- console . log ( "error: " + parentPlaceInfo . error ) ;
50
- // return getAddressForACProperties(properties);
51
- }
33
+ function getAddressForProperties ( properties : NodeProperties ) : string | null {
52
34
if ( ! isWheelmapProperties ( properties ) ) {
53
35
return getAddressForACProperties ( properties ) ;
54
36
}
@@ -61,11 +43,21 @@ type Props = {
61
43
userAgent : UAResult ;
62
44
} ;
63
45
64
- const PlaceAddress : React . FC < Props > = ( { feature, category, userAgent } ) => {
46
+ function PlaceAddress ( { feature, category, userAgent } : Props ) {
65
47
const placeName = placeNameFor ( feature . properties , category ) ;
66
48
const openInMaps = generateMapsUrl ( userAgent , feature , placeName ) ;
67
49
const showOnOsmUrl = generateShowOnOsmUrl ( feature ) ;
68
- const address = useAddressForProperties ( feature . properties ) ;
50
+
51
+ const appContext = React . useContext ( AppContext ) ;
52
+ const baseUrl = appContext ?. baseUrl ;
53
+ const appToken = appContext . app . tokenString ;
54
+
55
+ const { properties } = feature ;
56
+ const parentPlaceInfoId = isWheelmapProperties ( properties ) ? undefined : properties . parentPlaceInfoId ;
57
+ const url = parentPlaceInfoId && `${ baseUrl } /place-infos/${ parentPlaceInfoId } .json?appToken=${ appToken } ` ;
58
+ const { data : parentPlaceInfo } = useSWR < any > ( url , fetchJSON ) ;
59
+ const propertiesToUseForAddress = parentPlaceInfo ?. properties ?? feature . properties ;
60
+ const address = getAddressForProperties ( propertiesToUseForAddress ) ;
69
61
70
62
if ( ! feature || ! feature . properties ) return null ;
71
63
const addressString = address && address . replace ( / , $ / , "" ) . replace ( / ^ , / , "" ) ;
@@ -86,6 +78,6 @@ const PlaceAddress: React.FC<Props> = ({ feature, category, userAgent }) => {
86
78
) }
87
79
</ React . Fragment >
88
80
) ;
89
- } ;
81
+ }
90
82
91
83
export default PlaceAddress ;
0 commit comments