Skip to content

Commit

Permalink
v0.3.0: Added distance sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Lausch committed May 20, 2021
1 parent a20d6a8 commit a35f4af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lieferberlino",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"scripts": {
"install_dev": "docker-compose run web_dev npm install",
Expand Down
11 changes: 10 additions & 1 deletion src/components/LbCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<img :src="shop.image || 'https://via.placeholder.com/100'" :alt="`${shop.name}_logo`"/>
<div class="infos">
<h1>{{ shop.name }} <b-badge class="badge" pill :variant="shop.isOpen ? 'success' : 'danger'">{{ shop.isOpen ? 'Geöffnet' : 'Geschlossen' }}</b-badge></h1>
<h2>{{ format(shop.distance) }} entfernt</h2>
<h2>{{ shop.type }}</h2>
<h2>{{ shop.street }}</h2>
<h2>{{ shop.postalcode }} Ort</h2>
Expand All @@ -17,7 +18,15 @@
export default {
props: [
'shop'
]
],
methods: {
format (meter) {
if (meter > 1000) {
return `${(meter / 1000).toFixed(1)} km`
}
return `${meter} m`
}
}
}
</script>

Expand Down
18 changes: 14 additions & 4 deletions src/views/SearchResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ export default {
if (this.shopList.length === 0) {
this.$store.dispatch('getShops')
}
if (this.$store.state.location.coords.latitude === 0) {
this.$store.dispatch('getCurrentLocation')
}
},
computed: {
filteredList () {
const list = this.shopList.filter(shop => {
const location = {
latitude: parseInt(shop.location.split(';')[0]),
longitude: parseInt(shop.location.split(';')[1])
latitude: parseFloat(shop.location.split(';')[0]),
longitude: parseFloat(shop.location.split(';')[1])
}
const currentCoords = {
latitude: this.$store.state.location.coords.latitude,
longitude: this.$store.state.location.coords.longitude
}
const distance = getDistance(
this.$store.state.location.coords,
currentCoords,
location
)
Expand All @@ -63,7 +73,7 @@ export default {
return distance !== 0
})
// list.sort((shop, shop2) => shop.distance - shop2.distance)
list.sort((shop, shop2) => shop.distance - shop2.distance)
return list
},
Expand Down

0 comments on commit a35f4af

Please sign in to comment.