From f3c1f13792d78e3617e3d3f726d1324f3ea576ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 24 Sep 2018 23:46:01 +0200 Subject: Fixed select property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/views/Contacts.vue | 51 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'src/views') diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue index f6117b49..245711f6 100644 --- a/src/views/Contacts.vue +++ b/src/views/Contacts.vue @@ -201,15 +201,18 @@ export default { client.connect({ enableCardDAV: true }).then(() => { console.debug('Connected to dav!', client) this.$store.dispatch('getAddressbooks') - .then(() => { - // wait for all addressbooks to have fetch their contacts - Promise.all(this.addressbooks.map(addressbook => this.$store.dispatch('getContactsFromAddressBook', { addressbook }))) - .then(results => { - this.loading = false - this.selectFirstContactIfNone() - }) - // no need for a catch, the action does not throw - // and the error is handled there + .then((addressbooks) => { + + // No addressbooks? Create a new one! + if (addressbooks.length === 0) { + this.$store.dispatch('appendAddressbook', { displayName: t('contacts', 'Contacts') }) + .then(() => { + this.fetchContacts() + }) + // else, let's get those contacts! + } else { + this.fetchContacts() + } }) // check local storage for orderKey if (localStorage.getItem('orderKey')) { @@ -240,13 +243,15 @@ export default { contact.vCard.addPropertyWithValue('categories', this.selectedGroup) } this.$store.dispatch('addContact', contact) - this.$router.push({ - name: 'contact', - params: { - selectedGroup: this.selectedGroup, - selectedContact: contact.key - } - }) + .then(() => { + this.$router.push({ + name: 'contact', + params: { + selectedGroup: this.selectedGroup, + selectedContact: contact.key + } + }) + }) }, /** @@ -260,6 +265,20 @@ export default { this.$store.commit('sortContacts') }, + /** + * Fetch the contacts of each addressbooks + */ + fetchContacts() { + // wait for all addressbooks to have fetch their contacts + Promise.all(this.addressbooks.map(addressbook => this.$store.dispatch('getContactsFromAddressBook', { addressbook }))) + .then(results => { + this.loading = false + this.selectFirstContactIfNone() + }) + // no need for a catch, the action does not throw + // and the error is handled there + }, + /** * Select the first contact of the list * if none are selected already -- cgit v1.2.3