address selection: order preferred countries

This commit is contained in:
nobohan 2021-05-12 15:03:15 +02:00
parent fee37b5af3
commit b51575fc49
2 changed files with 8 additions and 2 deletions

View File

@ -6,7 +6,7 @@
const fetchCountries = () => {
console.log('<<< fetching countries');
const url = `/api/1.0/main/country.json`;
const url = `/api/1.0/main/country.json?item_per_page=1000`;
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
@ -21,6 +21,7 @@ const fetchCountries = () => {
const fetchCities = (country) => {
console.log('<<< fetching cities for', country);
//TODO use country
//TODO deal with huge number of postal code ... we should do suggestion...
const url = `/api/1.0/main/postal-code.json`;
return fetch(url)
.then(response => {

View File

@ -21,7 +21,12 @@ export default {
props: ['address', 'getCities'],
computed: {
countries() {
return this.address.loaded.countries; // TODO place Belgium and France first
const countries = this.address.loaded.countries;
let orderedCountries = [];
orderedCountries.push(...countries.filter(c => c.countryCode === 'FR'))
orderedCountries.push(...countries.filter(c => c.countryCode === 'BE'))
orderedCountries.push(...countries.filter(c => c.countryCode !== 'FR').filter(c => c.countryCode !== 'BE'))
return orderedCountries;
},
selected: {
set(value) {