pinafore/routes/_components/profile/AccountProfileFollow.html

101 lines
2.9 KiB
HTML
Raw Normal View History

<div class="account-profile-follow {shown ? 'shown' : ''}">
<IconButton
label={followLabel}
href={followIcon}
pressable="true"
pressed={following}
big="true"
on:click="onFollowButtonClick(event)"
2018-04-21 17:32:40 +02:00
ref:icon
/>
2018-04-01 01:51:18 +02:00
</div>
<style>
.account-profile-follow {
grid-area: follow;
align-self: flex-start;
display: none;
}
.account-profile-follow.shown {
display: block;
2018-04-01 01:51:18 +02:00
}
</style>
<script>
import IconButton from '../IconButton.html'
import { FOLLOW_BUTTON_ANIMATION } from '../../_static/animations'
import { store } from '../../_store/store'
import { setAccountFollowed } from '../../_actions/follow'
import { setAccountBlocked } from '../../_actions/block'
2018-04-01 01:51:18 +02:00
export default {
methods: {
2018-04-20 06:38:01 +02:00
async onFollowButtonClick (e) {
2018-04-01 01:51:18 +02:00
e.preventDefault()
e.stopPropagation()
let {
account,
accountId,
following,
followRequested,
blocking
} = this.get()
if (blocking) { // unblock
await setAccountBlocked(accountId, false)
} else { // follow/unfollow
let newFollowingValue = !(following || followRequested)
if (!account.locked) { // be optimistic, show the user that it succeeded
this.set({overrideFollowing: newFollowingValue})
}
2018-04-21 17:32:40 +02:00
if (newFollowingValue) {
this.refs.icon.animate(FOLLOW_BUTTON_ANIMATION)
}
await setAccountFollowed(accountId, newFollowingValue)
2018-04-03 18:51:34 +02:00
}
2018-04-01 01:51:18 +02:00
}
},
store: () => store,
2018-04-30 18:57:49 +02:00
data: () => ({
overrideFollowing: void 0
}),
2018-04-01 01:51:18 +02:00
computed: {
accountId: ({ account }) => account.id,
following: ({ relationship, overrideFollowing }) => {
2018-04-03 18:51:34 +02:00
if (typeof overrideFollowing === 'boolean') {
return overrideFollowing
}
return relationship && relationship.following
},
blocking: ({ relationship }) => relationship && relationship.blocking,
followRequested: ({ relationship }) => {
return relationship && relationship.requested
2018-04-01 01:51:18 +02:00
},
followLabel: ({ blocking, following, followRequested }) => {
if (blocking) {
return 'Unblock'
} else if (following) {
2018-04-01 01:51:18 +02:00
return 'Unfollow'
} else if (followRequested) {
return 'Unfollow (follow requested)'
} else {
return 'Follow'
}
},
followIcon: ({ blocking, following, followRequested }) => {
if (blocking) {
return '#fa-unlock'
} else if (following) {
2018-04-01 01:51:18 +02:00
return '#fa-user-times'
} else if (followRequested) {
return '#fa-hourglass'
} else {
return '#fa-user-plus'
}
},
shown: ({ verifyCredentials, relationship }) => {
return verifyCredentials && relationship && verifyCredentials.id !== relationship.id
2018-04-01 01:51:18 +02:00
}
},
components: {
IconButton
}
}
</script>