Skip to content

Commit

Permalink
refactor(City detail): add map display option (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Aug 22, 2024
1 parent 562842f commit c1113db
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export default {
],
DISPLAY_PARAM: 'display',
PRICE_DISPLAY_LIST: [
{ key: 'list', value: 'DisplayPriceList', icon: 'mdi-format-list-bulleted' },
{ key: 'list', value: 'DisplayList', icon: 'mdi-format-list-bulleted' },
{ key: 'map', value: 'DisplayPriceMap', icon: 'mdi-map-marker' },
],
LOCATION_DISPLAY_LIST: [
{ key: 'list', value: 'DisplayList', icon: 'mdi-format-list-bulleted' },
{ key: 'map', value: 'DisplayPriceMap', icon: 'mdi-map-marker' },
],
DATE_FULL_REGEX_MATCH: /(\d{4})-(\d{2})-(\d{2})/,
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
"Currency": "Currency",
"CurrencyMissing": "Currency missing",
"Display": "Display",
"DisplayList": "List",
"DisplayPriceList": "List",
"DisplayMap": "Map",
"DisplayPriceMap": "Map",
"Language": "Languages",
"LatestPrices": "Latest prices",
Expand Down
48 changes: 38 additions & 10 deletions src/views/CountryCityDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@
</h2>
<v-progress-circular v-if="loading" indeterminate :size="30" />
<LoadedCountChip v-if="!loading" :loadedCount="countryCityLocationList.length" :totalCount="countryCityLocationTotal" />
<DisplayMenu kind="price" :currentDisplay="currentDisplay" @update:currentDisplay="selectPriceDisplay($event)" />
</v-col>
</v-row>

<v-row class="mt-0">
<v-col v-for="location in countryCityLocationList" :key="location" cols="12" sm="6" md="4">
<LocationCard :location="location" :hideLocationOSMID="true" :hideCountryCity="true" height="100%" />
</v-col>
</v-row>
<v-window v-model="currentDisplay">
<v-window-item value="list">
<v-row class="mt-0 mb-1">
<v-col v-for="location in countryCityLocationList" :key="location" cols="12" sm="6" md="4">
<LocationCard :location="location" :hideLocationOSMID="true" :hideCountryCity="true" height="100%" />
</v-col>
</v-row>
</v-window-item>
<v-window-item value="map">
<v-row class="mt-0 mb-1">
<v-col style="height:400px">
<LeafletMap :locations="countryCityLocationList" />
</v-col>
</v-row>
</v-window-item>
</v-window>

<v-row v-if="countryCityLocationList.length < countryCityLocationTotal" class="mb-2">
<v-col align="center">
Expand All @@ -32,18 +44,22 @@

<script>
import { defineAsyncComponent } from 'vue'
import constants from '../constants'
import api from '../services/api'
export default {
components: {
CountryCard: defineAsyncComponent(() => import('../components/CountryCard.vue')),
LoadedCountChip: defineAsyncComponent(() => import('../components/LoadedCountChip.vue')),
LocationCard: defineAsyncComponent(() => import('../components/LocationCard.vue'))
DisplayMenu: defineAsyncComponent(() => import('../components/DisplayMenu.vue')),
LocationCard: defineAsyncComponent(() => import('../components/LocationCard.vue')),
LeafletMap: defineAsyncComponent(() => import('../components/LeafletMap.vue')),
},
data() {
return {
// filter & order
// order & display
currentOrder: '-price_count',
currentDisplay: constants.LOCATION_DISPLAY_LIST[0].key,
// data
country: null, // see init
countryCity: null, // see init
Expand All @@ -60,13 +76,20 @@ export default {
},
},
watch: {
$route (newCountryCity, oldCountryCity) {
if (oldCountryCity && newCountryCity && newCountryCity.name == 'country-city-detail' && oldCountryCity.fullPath != newCountryCity.fullPath) {
this.initCountryCity()
$route (newRoute, oldRoute) {
// only called when query changes to avoid having an API call when the path changes
// but ignore 'display' changes
if (oldRoute.path === newRoute.path) {
const oldRouteQueryFiltered = Object.fromEntries(Object.entries(oldRoute.query).filter(([key, value]) => key !== constants.DISPLAY_PARAM)) // eslint-disable-line no-unused-vars
const newRouteQueryFiltered = Object.fromEntries(Object.entries(newRoute.query).filter(([key, value]) => key !== constants.DISPLAY_PARAM)) // eslint-disable-line no-unused-vars
if (JSON.stringify(oldRouteQueryFiltered) !== JSON.stringify(newRouteQueryFiltered)) {
this.initCountryCity()
}
}
}
},
mounted() {
this.currentDisplay = this.$route.query[constants.DISPLAY_PARAM] || this.currentDisplay
this.initCountryCity()
},
methods: {
Expand All @@ -88,6 +111,11 @@ export default {
this.loading = false
})
},
selectPriceDisplay(displayKey) {
this.currentDisplay = displayKey
this.$router.push({ query: { ...this.$route.query, [constants.DISPLAY_PARAM]: this.currentDisplay } })
// this.initCountryCity() will NOT be called in watch $route
},
}
}
</script>

0 comments on commit c1113db

Please sign in to comment.