ALways show fresh relationship status in search.
This commit is contained in:
parent
6e60873a3d
commit
3fb7a7d099
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue