2019-02-26 15:34:40 +11:00
|
|
|
import FollowCard from '../follow_card/follow_card.vue'
|
2019-04-12 05:46:44 +10:00
|
|
|
import map from 'lodash/map'
|
|
|
|
|
2018-11-15 06:29:45 +11:00
|
|
|
const userSearch = {
|
|
|
|
components: {
|
2019-02-26 15:34:40 +11:00
|
|
|
FollowCard
|
2018-11-15 06:29:45 +11:00
|
|
|
},
|
|
|
|
props: [
|
|
|
|
'query'
|
|
|
|
],
|
|
|
|
data () {
|
|
|
|
return {
|
2018-12-29 06:39:54 +11:00
|
|
|
username: '',
|
2019-04-12 05:46:44 +10:00
|
|
|
userIds: [],
|
2019-02-23 05:37:02 +11:00
|
|
|
loading: false
|
2018-11-15 06:29:45 +11:00
|
|
|
}
|
|
|
|
},
|
2019-04-12 05:46:44 +10:00
|
|
|
computed: {
|
|
|
|
users () {
|
|
|
|
return this.userIds.map(userId => this.$store.getters.findUser(userId))
|
|
|
|
}
|
|
|
|
},
|
2018-11-15 06:29:45 +11:00
|
|
|
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-26 01:08:52 +11:00
|
|
|
this.$refs.userSearchInput.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
|
|
|
|
}
|
2019-02-23 05:37:02 +11:00
|
|
|
this.loading = true
|
2019-04-12 05:46:44 +10:00
|
|
|
this.$store.dispatch('searchUsers', query)
|
2018-11-15 06:29:45 +11:00
|
|
|
.then((res) => {
|
2019-02-23 05:37:02 +11:00
|
|
|
this.loading = false
|
2019-04-12 05:46:44 +10:00
|
|
|
this.userIds = map(res, 'id')
|
2018-11-15 06:29:45 +11:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default userSearch
|