ALways show fresh relationship status in search.

This commit is contained in:
lain 2019-03-22 12:58:04 +01:00
parent 6e60873a3d
commit 3fb7a7d099
1 changed files with 22 additions and 7 deletions

View File

@ -1,5 +1,7 @@
import FollowCard from '../follow_card/follow_card.vue'
import userSearchApi from '../../services/new_api/user_search.js'
import { map, each } from 'lodash'
const userSearch = {
components: {
FollowCard
@ -10,13 +12,18 @@ const userSearch = {
data () {
return {
username: '',
users: [],
userIds: [],
loading: false
}
},
mounted () {
this.search(this.query)
},
computed: {
users () {
return map(this.userIds, (id) => this.$store.state.users.usersObject[id])
}
},
watch: {
query (newV) {
this.search(newV)
@ -27,17 +34,25 @@ const userSearch = {
this.$router.push({ name: 'user-search', query: { query } })
this.$refs.userSearchInput.focus()
},
search (query) {
async search (query) {
if (!query) {
this.users = []
return
}
this.loading = true
userSearchApi.search({query, store: this.$store})
.then((res) => {
this.loading = false
this.users = res
try {
this.userIds = []
const users = await userSearchApi.search({ query, store: this.$store })
this.$store.commit('addNewUsers', users)
each(users, ({ id }) => {
this.userIds.push(id)
this.$store.dispatch('fetchUserRelationship', id)
})
} catch (e) {
console.error(e)
} finally {
this.loading = false
}
}
}
}