pleroma-fe/src/components/user_search/user_search.js

46 lines
868 B
JavaScript
Raw Normal View History

import FollowCard from '../follow_card/follow_card.vue'
2018-11-14 20:29:45 +01:00
import userSearchApi from '../../services/new_api/user_search.js'
const userSearch = {
components: {
FollowCard
2018-11-14 20:29:45 +01:00
},
props: [
'query'
],
data () {
return {
username: '',
2019-02-22 19:37:02 +01:00
users: [],
loading: false
2018-11-14 20:29:45 +01:00
}
},
mounted () {
this.search(this.query)
},
watch: {
query (newV) {
this.search(newV)
}
},
methods: {
newQuery (query) {
this.$router.push({ name: 'user-search', query: { query } })
2019-02-25 15:08:52 +01:00
this.$refs.userSearchInput.focus()
},
2018-11-14 20:29:45 +01:00
search (query) {
if (!query) {
this.users = []
return
}
2019-02-22 19:37:02 +01:00
this.loading = true
2018-11-14 20:29:45 +01:00
userSearchApi.search({query, store: this.$store})
.then((res) => {
2019-02-22 19:37:02 +01:00
this.loading = false
2018-11-14 20:29:45 +01:00
this.users = res
})
}
}
}
export default userSearch