remove blocked one from the results on real time

This commit is contained in:
taehoon 2019-04-02 14:27:22 -04:00
parent 33467880ed
commit 9184435887
2 changed files with 13 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import reject from 'lodash/reject'
import map from 'lodash/map'
import BlockCard from '../block_card/block_card.vue'
import userSearchApi from '../../services/new_api/user_search.js'
@ -16,6 +17,14 @@ export default {
resultsVisible: false
}
},
computed: {
filtered () {
return reject(this.results, (userId) => {
const user = this.$store.getters.findUser(userId)
return !user || user.statusnet_blocking || user.id === this.$store.state.users.currentUser.id
})
}
},
watch: {
query (val) {
this.fetchResults(val)
@ -29,12 +38,8 @@ export default {
if (query) {
userSearchApi.search({query, store: this.$store})
.then((users) => {
const filteredUsers = reject(users, (user) => {
return user.statusnet_blocking || user.id === this.$store.state.users.currentUser.id
})
this.$store.dispatch('addNewUsers', filteredUsers)
this.results = filteredUsers
this.resultsVisible = true
this.$store.dispatch('addNewUsers', users)
this.results = map(users, 'id')
})
}
}, debounceMilliseconds)

View File

@ -1,8 +1,8 @@
<template>
<div class="user-autosuggest" v-click-outside="onClickOutside">
<input v-model="query" placeholder="Search whom you want to block" @click="onInputClick" class="user-autosuggest-input" />
<div class="user-autosuggest-results" v-if="resultsVisible && results.length > 0">
<BlockCard v-for="user in results" :key="user.id" :userId="user.id"/>
<div class="user-autosuggest-results" v-if="resultsVisible && filtered.length > 0">
<BlockCard v-for="userId in filtered" :key="userId" :userId="userId"/>
</div>
</div>
</template>