Skip to content

Commit

Permalink
feat(location detail): add country flag (#81)
Browse files Browse the repository at this point in the history
* location detail: show flag next to location name

* Refactor getLocationTitle to utils

* Add name_original key. Cleanup
  • Loading branch information
raphodn authored Dec 29, 2023
1 parent d2f6b31 commit 62c9bb7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/PriceCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default {
},
getPriceLocationTitle() {
if (this.price.location) {
return `${this.price.location.osm_name}, ${this.price.location.osm_address_city}`
return utils.getLocationTitle(this.price.location)
}
return this.price.location_id
},
Expand Down
2 changes: 1 addition & 1 deletion src/data/countries-with-emoji.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ function prettyRelativeDateTime(dateTimeString, short=false) {
}

function getCountryEmojiFromName(countryString) {
const country = CountriesWithEmoji.find(c => c.name === countryString)
const country = CountriesWithEmoji.find(c => c.name === countryString || (c.name_original && c.name_original.length && c.name_original.indexOf(countryString) > -1))
return country ? country.emoji : null
}

function getLocationTitle(locationObject, withEmoji=false) {
let locationTitle = `${locationObject.osm_name}, ${locationObject.osm_address_city || ''}`
if (withEmoji) {
locationTitle += ` ${getCountryEmojiFromName(locationObject.osm_address_country) || ''}`
}
return locationTitle
}


export default {
addObjectToArray,
prettyDate,
prettyRelativeDateTime,
getCountryEmojiFromName,
getLocationTitle,
}
3 changes: 2 additions & 1 deletion src/views/LocationDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<script>
import api from '../services/api'
import utils from '../utils.js'
import PriceCard from '../components/PriceCard.vue'
export default {
Expand Down Expand Up @@ -77,7 +78,7 @@ export default {
},
getLocationTitle(location) {
if (location) {
return `${location.osm_name}, ${location.osm_address_city}`
return utils.getLocationTitle(location, true)
}
return this.$route.params.id
},
Expand Down

0 comments on commit 62c9bb7

Please sign in to comment.