Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo contact deletion from list #1025

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions css/ContactsListItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
.app-content-list-item.deleted {
.app-content-list-item-icon__avatar {
filter: brightness(.8) grayscale(1);
}
.app-content-list-item-line-one {
text-decoration: line-through;
}
}

.app-content-list-item-icon {
overflow: hidden;
Expand Down
33 changes: 27 additions & 6 deletions src/components/ContactsList/ContactsListItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :id="id" :class="{active: selectedContact === contact.key}"
<div :id="id" :class="{active: selectedContact === contact.key, deleted: deleteTimeout}"
tabindex="0"
class="app-content-list-item" @click.prevent.stop="selectContact" @keypress.enter.prevent.stop="selectContact">
<!-- keyboard accessibility will focus the input and not the label -->
Expand All @@ -8,19 +8,25 @@
class="app-content-list-item-checkbox checkbox" @keypress.enter.space.prevent.stop="toggleSelect">
<label :for="contact.key" @click.prevent.stop="toggleSelect" @keypress.enter.space.prevent.stop="toggleSelect" />
-->
<div :style="{ 'backgroundColor': colorAvatar }" class="app-content-list-item-icon">
<div :style="{ 'backgroundColor': !deleteTimeout ? colorAvatar : 'grey' }" class="app-content-list-item-icon">
{{ contact.displayName | firstLetter }}
<!-- try to fetch the avatar only if the contact exists on the server -->
<div v-if="hasPhoto" :style="{ 'backgroundImage': avatarUrl }" class="app-content-list-item-icon__avatar" />
</div>

<!-- contact data -->
<div class="app-content-list-item-line-one">
{{ contact.displayName }}
</div>
<div v-if="contact.email" class="app-content-list-item-line-two">
<div v-if="contact.email && !deleteTimeout" class="app-content-list-item-line-two">
{{ contact.email }}
</div>
<div v-if="!contact.addressbook.readOnly" class="icon-delete" tabindex="0"

<!-- delete and undo actions -->
<div v-if="!contact.addressbook.readOnly && !deleteTimeout" class="icon-delete" tabindex="0"
@click.prevent.stop="deleteContact" @keypress.enter.prevent.stop="deleteContact" />
<div v-else-if="deleteTimeout" class="icon-history" tabindex="0"
@click.prevent.stop="cancelDeletion" @keypress.enter.prevent.stop="cancelDeletion" />
</div>
</template>

Expand All @@ -42,6 +48,11 @@ export default {
required: true
}
},
data() {
return {
deleteTimeout: null
}
},
computed: {
selectedGroup() {
return this.$route.params.selectedGroup
Expand Down Expand Up @@ -72,6 +83,9 @@ export default {
}
},
avatarUrl() {
if (this.contact.photo) {
return `url(${this.contact.photo})`
}
return `url(${this.contact.url}?photo)`
}
},
Expand All @@ -89,8 +103,15 @@ export default {
* Dispatch contact deletion request
*/
deleteContact() {
this.$store.dispatch('deleteContact', { contact: this.contact })
this.$emit('deleted', this.index)
this.deleteTimeout = setTimeout(() => {
this.$store.dispatch('deleteContact', { contact: this.contact })
this.$emit('deleted', this.index)
}, 7000)
},

cancelDeletion() {
clearTimeout(this.deleteTimeout)
this.deleteTimeout = null
},

/**
Expand Down