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

View file

@ -1,8 +1,8 @@
<template> <template>
<div class="user-autosuggest" v-click-outside="onClickOutside"> <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" /> <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"> <div class="user-autosuggest-results" v-if="resultsVisible && filtered.length > 0">
<BlockCard v-for="user in results" :key="user.id" :userId="user.id"/> <BlockCard v-for="userId in filtered" :key="userId" :userId="userId"/>
</div> </div>
</div> </div>
</template> </template>