2019-04-02 18:01:21 +00:00
|
|
|
import reject from 'lodash/reject'
|
2019-04-02 17:49:48 +00:00
|
|
|
import BlockCard from '../block_card/block_card.vue'
|
2019-04-02 10:12:31 +00:00
|
|
|
import userSearchApi from '../../services/new_api/user_search.js'
|
|
|
|
|
2019-04-02 16:31:45 +00:00
|
|
|
const debounceMilliseconds = 500
|
|
|
|
|
2019-04-02 10:12:31 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
2019-04-02 17:49:48 +00:00
|
|
|
BlockCard
|
2019-04-02 10:12:31 +00:00
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2019-04-02 16:31:45 +00:00
|
|
|
query: '',
|
2019-04-02 10:12:31 +00:00
|
|
|
results: [],
|
2019-04-02 17:18:36 +00:00
|
|
|
timeout: null,
|
|
|
|
resultsVisible: false
|
2019-04-02 16:31:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
query (val) {
|
|
|
|
this.fetchResults(val)
|
2019-04-02 10:12:31 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
fetchResults (query) {
|
|
|
|
clearTimeout(this.timeout)
|
|
|
|
this.timeout = setTimeout(() => {
|
2019-04-02 16:31:45 +00:00
|
|
|
this.results = []
|
|
|
|
if (query) {
|
|
|
|
userSearchApi.search({query, store: this.$store})
|
2019-04-02 18:01:21 +00:00
|
|
|
.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
|
2019-04-02 17:18:36 +00:00
|
|
|
this.resultsVisible = true
|
|
|
|
})
|
2019-04-02 16:31:45 +00:00
|
|
|
}
|
|
|
|
}, debounceMilliseconds)
|
2019-04-02 17:18:36 +00:00
|
|
|
},
|
|
|
|
onInputClick () {
|
|
|
|
this.resultsVisible = true
|
|
|
|
},
|
|
|
|
onClickOutside () {
|
|
|
|
this.resultsVisible = false
|
2019-04-02 10:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|