Skip to content

Commit

Permalink
refactor: new LocationCard component (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 31, 2024
1 parent fd93dde commit 5c25493
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 36 deletions.
46 changes: 46 additions & 0 deletions src/components/LocationCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<v-card
:title="getLocationTitle(location)"
:subtitle="location ? location.osm_display_name : ''"
:prepend-icon="location ? 'mdi-map-marker-outline' : 'mdi-map-marker-remove-variant'"
@click="goToLocation(location)">
<v-card-text v-if="location">
<PriceCountChip :count="location.price_count" :withLabel="true"></PriceCountChip>
</v-card-text>
</v-card>
</template>

<script>
import { defineAsyncComponent } from 'vue'
import utils from '../utils.js'
export default {
components: {
'PriceCountChip': defineAsyncComponent(() => import('../components/PriceCountChip.vue')),
},
props: {
location: {
type: Object,
required: true
},
readonly: {
type: Boolean,
default: false
}
},
methods: {
getLocationTitle(location) {
if (location) {
return utils.getLocationTitle(location, true, false, true, true)
}
return this.$route.params.id
},
goToLocation(location) {
if (this.readonly) {
return
}
this.$router.push({ path: `/locations/${location.id}` })
},
}
}
</script>
19 changes: 3 additions & 16 deletions src/views/LocationDetail.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<template>
<v-row>
<v-col cols="12" sm="6">
<v-card
:title="getLocationTitle(location)"
:subtitle="location ? location.osm_display_name : ''"
:prepend-icon="location ? 'mdi-map-marker-outline' : 'mdi-map-marker-remove-variant'">
<v-card-text>
<PriceCountChip :count="locationPriceTotal" :withLabel="true"></PriceCountChip>
</v-card-text>
</v-card>
<LocationCard :location="location" readonly></LocationCard>
</v-col>
</v-row>

Expand Down Expand Up @@ -49,14 +42,14 @@
</template>

<script>
import { defineAsyncComponent } from 'vue'
import api from '../services/api'
import utils from '../utils.js'
import { defineAsyncComponent } from 'vue'
import constants from '../constants'
export default {
components: {
'PriceCountChip': defineAsyncComponent(() => import('../components/PriceCountChip.vue')),
'LocationCard': defineAsyncComponent(() => import('../components/LocationCard.vue')),
'FilterMenu': defineAsyncComponent(() => import('../components/FilterMenu.vue')),
'OrderMenu': defineAsyncComponent(() => import('../components/OrderMenu.vue')),
'PriceCard': defineAsyncComponent(() => import('../components/PriceCard.vue')),
Expand Down Expand Up @@ -123,12 +116,6 @@ export default {
this.loading = false
})
},
getLocationTitle(location) {
if (location) {
return utils.getLocationTitle(location, true, false, true, true)
}
return this.$route.params.id
},
togglePriceFilter(filterKey) {
this.currentFilter = this.currentFilter ? '' : filterKey
this.$router.push({ query: { ...this.$route.query, [constants.FILTER_PARAM]: this.currentFilter } })
Expand Down
23 changes: 3 additions & 20 deletions src/views/LocationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@

<v-row class="mt-0">
<v-col cols="12" sm="6" md="4" v-for="location in locationList" :key="location">
<v-card
:title="getLocationTitle(location)"
:subtitle="location.osm_display_name"
prepend-icon="mdi-map-marker-outline"
elevation="1"
height="100%"
@click="goToLocation(location)">
<v-card-text>
<PriceCountChip :count="location.price_count" :withLabel="true"></PriceCountChip>
</v-card-text>
</v-card>
<LocationCard :location="location" height="100%"></LocationCard>
</v-col>
</v-row>

Expand All @@ -36,13 +26,12 @@
</template>

<script>
import api from '../services/api'
import utils from '../utils.js'
import { defineAsyncComponent } from 'vue'
import api from '../services/api'
export default {
components: {
'PriceCountChip': defineAsyncComponent(() => import('../components/PriceCountChip.vue')),
'LocationCard': defineAsyncComponent(() => import('../components/LocationCard.vue')),
},
data() {
return {
Expand Down Expand Up @@ -73,12 +62,6 @@ export default {
this.loading = false
})
},
getLocationTitle(location) {
return utils.getLocationTitle(location, true, false, true, true)
},
goToLocation(location) {
this.$router.push({ path: `/locations/${location.id}` })
},
}
}
</script>

0 comments on commit 5c25493

Please sign in to comment.