From af174d3bf9c0f6b048e7f81f2a6e01e4d88eb1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 28 Sep 2018 15:17:27 +0200 Subject: Scroll to selected contact MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/components/ContactDetails.vue | 67 +++++++++++++++----------- src/components/ContentList/ContentListItem.vue | 11 +++-- src/models/contact.js | 2 +- 3 files changed, 49 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index 57175048..e59fb130 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -343,6 +343,7 @@ export default { /** * Select a contac, and update the localContact * Fetch updated data if necessary + * Scroll to the selected contact if exists * * @param {string} uid the contact uid */ @@ -351,33 +352,45 @@ export default { this.loadingData = true let contact = this.$store.getters.getContact(uid) - // if contact exists AND if exists on server - if (contact && contact.dav) { - this.$store.dispatch('fetchFullContact', { contact }) - .then(() => { - // create empty contact and copy inner data - let localContact = new Contact( - 'BEGIN:VCARD\nUID:' + contact.uid + '\nEND:VCARD', - contact.addressbook - ) - localContact.updateContact(contact.jCal) - this.localContact = localContact - this.loadingData = false - }) - .catch((error) => { - OC.Notification.showTemporary(t('contacts', 'The contact doesn\'t exists anymore on the server.')) - console.error(error) - // trigger a local deletion from the store only - this.$store.dispatch('deleteContact', { contact: this.contact, dav: false }) - }) - } else if (contact) { - // create empty contact and copy inner data - // wait for an update to really push the contact on the server! - this.localContact = new Contact( - 'BEGIN:VCARD\nUID:' + contact.uid + '\nEND:VCARD', - contact.addressbook - ) - this.loadingData = false + if (contact) { + // if contact exists AND if exists on server + if (contact.dav) { + this.$store.dispatch('fetchFullContact', { contact }) + .then(() => { + // create empty contact and copy inner data + let localContact = new Contact( + 'BEGIN:VCARD\nUID:' + contact.uid + '\nEND:VCARD', + contact.addressbook + ) + localContact.updateContact(contact.jCal) + this.localContact = localContact + this.loadingData = false + }) + .catch((error) => { + OC.Notification.showTemporary(t('contacts', 'The contact doesn\'t exists anymore on the server.')) + console.error(error) + // trigger a local deletion from the store only + this.$store.dispatch('deleteContact', { contact: this.contact, dav: false }) + }) + } else { + // create empty contact and copy inner data + // wait for an update to really push the contact on the server! + this.localContact = new Contact( + 'BEGIN:VCARD\nUID:' + contact.uid + '\nEND:VCARD', + contact.addressbook + ) + this.loadingData = false + } + + // scroll to selected contact if any + let list = document.getElementById('contacts-list') + let item = document.querySelector('#' + btoa(contact.key).slice(0, -2)) + let isAbove = list.scrollTop > item.offsetTop + let isUnder = item.offsetTop + item.offsetHeight > list.scrollTop + list.offsetHeight + // check if contact outside visible list area + if (item && (isAbove || isUnder)) { + list.scrollTo(0, item.offsetTop - item.offsetHeight / 2) + } } }, diff --git a/src/components/ContentList/ContentListItem.vue b/src/components/ContentList/ContentListItem.vue index 88e6bb78..f7ecd1db 100644 --- a/src/components/ContentList/ContentListItem.vue +++ b/src/components/ContentList/ContentListItem.vue @@ -1,6 +1,6 @@