Skip to content

Commit

Permalink
Merge pull request #1023 from nextcloud/fix/list/search
Browse files Browse the repository at this point in the history
Fix search filter in list
  • Loading branch information
skjnldsv authored Mar 28, 2019
2 parents 73a315c + c0ebed1 commit 2c85fba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions src/components/ContactsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
ref="scroller"
:class="{'icon-loading': loading, showdetails: selectedContact}"
class="app-content-list"
:items="list"
:items="filteredList"
:item-size="itemHeight"
key-field="key">
<template v-slot="{ item, index }">
<contacts-list-item :key="item.key"
:contact="contacts[item.key]" :search-query="searchQuery" :index="index"
<contacts-list-item
:key="item.key"
:contact="contacts[item.key]"
:index="index"
@deleted="selectContact" />
</template>
</recycle-scroller>
Expand Down Expand Up @@ -83,6 +85,9 @@ export default {
},
selectedGroup() {
return this.$route.params.selectedGroup
},
filteredList() {
return this.list.filter(contact => this.matchSearch(this.contacts[contact.key]))
}
},

Expand Down Expand Up @@ -140,6 +145,19 @@ export default {
scroller.scrollTop = scroller.scrollTop + pos
}
}
},

/**
* Is this matching the current search ?
*
* @param {Contact} contact the contact to search
* @returns {boolean}
*/
matchSearch(contact) {
if (this.searchQuery.trim() !== '') {
return contact.searchData.toString().toLowerCase().search(this.searchQuery.trim().toLowerCase()) !== -1
}
return true
}
}
}
Expand Down
18 changes: 1 addition & 17 deletions src/components/ContactsList/ContactsListItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="matchSearch" :id="id" :class="{active: selectedContact === contact.key}"
<div :id="id" :class="{active: selectedContact === contact.key}"
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 Down Expand Up @@ -40,10 +40,6 @@ export default {
contact: {
type: Object,
required: true
},
searchQuery: {
type: String,
default: ''
}
},
computed: {
Expand All @@ -63,18 +59,6 @@ export default {
return this.contact.dav && (this.contact.dav.hasphoto || this.contact.photo)
},
/**
* Is this matching the current search ?
*
* @returns {boolean}
*/
matchSearch() {
if (this.searchQuery.trim() !== '') {
return this.contact.searchData.toString().toLowerCase().search(this.searchQuery.toLowerCase()) !== -1
}
return true
},
/**
* avatar color based on server toRgb method and the displayName
* @returns {string} the color in css format
Expand Down

0 comments on commit 2c85fba

Please sign in to comment.