2018-11-15 06:29:45 +11:00
|
|
|
import UserCard from '../user_card/user_card.vue'
|
|
|
|
import userSearchApi from '../../services/new_api/user_search.js'
|
|
|
|
const userSearch = {
|
|
|
|
components: {
|
|
|
|
UserCard
|
|
|
|
},
|
|
|
|
props: [
|
|
|
|
'query'
|
|
|
|
],
|
|
|
|
data () {
|
|
|
|
return {
|
2018-12-29 06:39:54 +11:00
|
|
|
username: '',
|
2018-11-15 06:29:45 +11:00
|
|
|
users: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
this.search(this.query)
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
query (newV) {
|
|
|
|
this.search(newV)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2018-12-29 06:39:54 +11:00
|
|
|
newQuery (query) {
|
|
|
|
this.$router.push({ name: 'user-search', query: { query } })
|
2019-02-22 06:20:46 +11:00
|
|
|
this.$refs.username.focus()
|
2018-12-29 06:39:54 +11:00
|
|
|
},
|
2018-11-15 06:29:45 +11:00
|
|
|
search (query) {
|
2018-12-29 06:39:54 +11:00
|
|
|
if (!query) {
|
|
|
|
this.users = []
|
|
|
|
return
|
|
|
|
}
|
2018-11-15 06:29:45 +11:00
|
|
|
userSearchApi.search({query, store: this.$store})
|
|
|
|
.then((res) => {
|
|
|
|
this.users = res
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default userSearch
|