2019-04-02 21:12:31 +11:00
|
|
|
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
|
|
|
|
import userSearchApi from '../../services/new_api/user_search.js'
|
|
|
|
|
2019-04-03 03:31:45 +11:00
|
|
|
const debounceMilliseconds = 500
|
|
|
|
|
2019-04-02 21:12:31 +11:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
BasicUserCard
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2019-04-03 03:31:45 +11:00
|
|
|
query: '',
|
2019-04-02 21:12:31 +11:00
|
|
|
results: [],
|
2019-04-03 04:18:36 +11:00
|
|
|
timeout: null,
|
|
|
|
resultsVisible: false
|
2019-04-03 03:31:45 +11:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
query (val) {
|
|
|
|
this.fetchResults(val)
|
2019-04-02 21:12:31 +11:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
fetchResults (query) {
|
|
|
|
clearTimeout(this.timeout)
|
|
|
|
this.timeout = setTimeout(() => {
|
2019-04-03 03:31:45 +11:00
|
|
|
this.results = []
|
|
|
|
if (query) {
|
|
|
|
userSearchApi.search({query, store: this.$store})
|
2019-04-03 04:18:36 +11:00
|
|
|
.then((data) => {
|
|
|
|
this.results = data
|
|
|
|
this.resultsVisible = true
|
|
|
|
})
|
2019-04-03 03:31:45 +11:00
|
|
|
}
|
|
|
|
}, debounceMilliseconds)
|
2019-04-03 04:18:36 +11:00
|
|
|
},
|
|
|
|
onInputClick () {
|
|
|
|
this.resultsVisible = true
|
|
|
|
},
|
|
|
|
onClickOutside () {
|
|
|
|
this.resultsVisible = false
|
2019-04-02 21:12:31 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|