Skip to content

Commit

Permalink
refactor(Location): get country emoji from country_code instead of co…
Browse files Browse the repository at this point in the history
…untry (#580)
  • Loading branch information
raphodn authored May 22, 2024
1 parent 5f40587 commit ba3c075
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/PriceLocationChip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
},
priceLocationEmoji() {
if (this.price && this.price.location) {
return utils.getCountryEmojiFromName(this.price.location.osm_address_country)
return utils.getCountryEmojiFromCode(this.price.location.osm_address_country_code)
}
return null
}
Expand Down
9 changes: 8 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ function getCountryEmojiFromName(countryString) {
return country ? country.emoji : null
}

function getCountryEmojiFromCode(countryCode) {
const country = CountriesWithEmoji.find(c => c.code === countryCode)
return country ? country.emoji : null
}

function getLocationName(locationObject) {
// Photon
if (locationObject.properties) {
Expand Down Expand Up @@ -158,7 +163,8 @@ function getLocationTitle(locationObject, withName=true, withRoad=false, withCit
locationTitle += getLocationCity(locationObject)
}
if (withEmoji) {
locationTitle += ` ${getCountryEmojiFromName(locationObject.osm_address_country) || ''}`
// locationTitle += ` ${getCountryEmojiFromName(locationObject.osm_address_country) || ''}`
locationTitle += ` ${getCountryEmojiFromCode(locationObject.osm_address_country_code) || ''}`
}
return locationTitle
}
Expand Down Expand Up @@ -235,6 +241,7 @@ export default {
getLocaleCategoryTagName,
getLocaleOriginTags,
getCountryEmojiFromName,
getCountryEmojiFromCode,
getLocationTitle,
getLocationID,
getLocationType,
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/pitted_apricot_prices.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
"id": 32,
"osm_name": "Monoprix",
"osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38000",
"osm_address_city": "Grenoble",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1904063,
"osm_lon": 5.7286464,
"created": "2024-02-09T17:43:00.113125+01:00",
Expand Down Expand Up @@ -87,9 +90,12 @@
"id": 32,
"osm_name": "Monoprix",
"osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38000",
"osm_address_city": "Grenoble",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1904063,
"osm_lon": 5.7286464,
"created": "2024-02-09T17:43:00.113125+01:00",
Expand Down
30 changes: 30 additions & 0 deletions tests/fixtures/prices.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
"id": 32,
"osm_name": "Monoprix",
"osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38000",
"osm_address_city": "Grenoble",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1904063,
"osm_lon": 5.7286464,
"created": "2024-02-09T17:43:00.113125+01:00",
Expand Down Expand Up @@ -104,9 +107,12 @@
"id": 32,
"osm_name": "Monoprix",
"osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38000",
"osm_address_city": "Grenoble",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1904063,
"osm_lon": 5.7286464,
"created": "2024-02-09T17:43:00.113125+01:00",
Expand Down Expand Up @@ -152,9 +158,12 @@
"id": 32,
"osm_name": "Monoprix",
"osm_display_name": "Monoprix, Rue Lafayette, Hyper Centre, Secteur 2, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38000, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38000",
"osm_address_city": "Grenoble",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1904063,
"osm_lon": 5.7286464,
"created": "2024-02-09T17:43:00.113125+01:00",
Expand Down Expand Up @@ -217,9 +226,12 @@
"id": 36,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.805746+01:00",
Expand Down Expand Up @@ -282,9 +294,12 @@
"id": 36,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.805746+01:00",
Expand Down Expand Up @@ -347,9 +362,12 @@
"id": 36,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.805746+01:00",
Expand Down Expand Up @@ -412,9 +430,12 @@
"id": 38,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.807454+01:00",
Expand Down Expand Up @@ -477,9 +498,12 @@
"id": 38,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.807454+01:00",
Expand Down Expand Up @@ -542,9 +566,12 @@
"id": 36,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.805746+01:00",
Expand Down Expand Up @@ -607,9 +634,12 @@
"id": 38,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.807454+01:00",
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/product_3011360030498_prices.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@
"id": 38,
"osm_name": "E. Leclerc",
"osm_display_name": "E. Leclerc, V 64, Pré Nouvel, Échirolles, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38130, France",
"osm_tag_key": "shop",
"osm_tag_value": "supermarket",
"osm_address_postcode": "38130",
"osm_address_city": "Échirolles",
"osm_address_country": "France",
"osm_address_country_code": "FR",
"osm_lat": 45.1498691,
"osm_lon": 5.6920308,
"created": "2024-02-18T19:39:23.807454+01:00",
Expand Down

0 comments on commit ba3c075

Please sign in to comment.