diff options
Diffstat (limited to 'src/views/Contacts.vue')
-rw-r--r-- | src/views/Contacts.vue | 51 |
1 files changed, 35 insertions, 16 deletions
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 + } + }) + }) }, /** @@ -261,6 +266,20 @@ export default { }, /** + * 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 */ |