pinafore/routes/_components/profile/AccountProfileFollow.html

81 lines
2.4 KiB
HTML
Raw Normal View History

2018-03-31 23:51:18 +00:00
<div class="account-profile-follow">
{{#if verifyCredentials && relationship && verifyCredentials.id !== relationship.id}}
<IconButton
label="{{followLabel}}"
href="{{followIcon}}"
pressable="true"
pressed="{{following}}"
big="true"
on:click="onFollowButtonClick(event)"
animation="{{animateFollowButton && followButtonAnimation}}"
/>
{{/if}}
</div>
<style>
.account-profile-follow {
grid-area: follow;
align-self: flex-start;
}
</style>
<script>
import IconButton from '../IconButton.html'
import { FOLLOW_BUTTON_ANIMATION } from '../../_static/animations'
import { store } from '../../_store/store'
import { setAccountFollowed } from '../../_actions/follow'
export default {
methods: {
async onFollowButtonClick(e) {
e.preventDefault()
e.stopPropagation()
2018-04-03 16:51:34 +00:00
let account = this.get('account')
2018-03-31 23:51:18 +00:00
let accountId = this.get('accountId')
let following = this.get('following')
let followRequested = this.get('followRequested')
this.set({animateFollowButton: true})
2018-04-03 16:51:34 +00:00
let newFollowingValue = !(following || followRequested)
await setAccountFollowed(accountId, newFollowingValue)
if (!account.locked) { // be optimistic, show the user that it succeeded
2018-04-04 00:27:30 +00:00
this.set({overrideFollowing: newFollowingValue})
2018-04-03 16:51:34 +00:00
}
2018-03-31 23:51:18 +00:00
}
},
store: () => store,
data: () => ({
followButtonAnimation: FOLLOW_BUTTON_ANIMATION
}),
computed: {
accountId: (account) => account.id,
2018-04-03 16:51:34 +00:00
following: (relationship, overrideFollowing) => {
if (typeof overrideFollowing === 'boolean') {
return overrideFollowing
}
return relationship && relationship.following
},
2018-03-31 23:51:18 +00:00
followRequested: (relationship, account) => {
return relationship && relationship.requested && account && account.locked
},
followLabel: (following, followRequested) => {
if (following) {
return 'Unfollow'
} else if (followRequested) {
return 'Unfollow (follow requested)'
} else {
return 'Follow'
}
},
followIcon: (following, followRequested) => {
if (following) {
return '#fa-user-times'
} else if (followRequested) {
return '#fa-hourglass'
} else {
return '#fa-user-plus'
}
}
},
components: {
IconButton
}
}
</script>