2019-02-26 03:51:04 +00:00
|
|
|
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
|
2019-03-19 18:36:27 +00:00
|
|
|
import RemoteFollow from '../remote_follow/remote_follow.vue'
|
2019-02-26 03:51:04 +00:00
|
|
|
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'
|
|
|
|
|
|
|
|
const FollowCard = {
|
|
|
|
props: [
|
|
|
|
'user',
|
|
|
|
'noFollowsYou'
|
|
|
|
],
|
|
|
|
data () {
|
|
|
|
return {
|
2019-02-26 15:14:12 +00:00
|
|
|
inProgress: false,
|
2019-02-26 03:51:04 +00:00
|
|
|
requestSent: false,
|
|
|
|
updated: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2019-03-19 18:36:27 +00:00
|
|
|
BasicUserCard,
|
|
|
|
RemoteFollow
|
2019-02-26 03:51:04 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isMe () { return this.$store.state.users.currentUser.id === this.user.id },
|
|
|
|
following () { return this.updated ? this.updated.following : this.user.following },
|
|
|
|
showFollow () {
|
|
|
|
return !this.following || this.updated && !this.updated.following
|
2019-03-19 18:36:27 +00:00
|
|
|
},
|
|
|
|
loggedIn () {
|
|
|
|
return this.$store.state.users.currentUser
|
2019-02-26 03:51:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
followUser () {
|
2019-02-26 15:14:12 +00:00
|
|
|
this.inProgress = true
|
2019-02-26 03:51:04 +00:00
|
|
|
requestFollow(this.user, this.$store).then(({ sent, updated }) => {
|
2019-02-26 15:14:12 +00:00
|
|
|
this.inProgress = false
|
2019-02-26 03:51:04 +00:00
|
|
|
this.requestSent = sent
|
|
|
|
this.updated = updated
|
|
|
|
})
|
|
|
|
},
|
|
|
|
unfollowUser () {
|
2019-02-26 15:14:12 +00:00
|
|
|
this.inProgress = true
|
2019-02-26 03:51:04 +00:00
|
|
|
requestUnfollow(this.user, this.$store).then(({ updated }) => {
|
2019-02-26 15:14:12 +00:00
|
|
|
this.inProgress = false
|
2019-02-26 03:51:04 +00:00
|
|
|
this.updated = updated
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FollowCard
|