2018-05-02 00:05:36 +00:00
|
|
|
<div class="account-profile-follow {shown ? 'shown' : ''}">
|
2018-04-12 05:55:04 +00:00
|
|
|
<IconButton
|
2018-05-02 00:05:36 +00:00
|
|
|
label={followLabel}
|
|
|
|
href={followIcon}
|
2018-04-12 05:55:04 +00:00
|
|
|
pressable="true"
|
2018-05-02 00:05:36 +00:00
|
|
|
pressed={following}
|
2018-04-12 05:55:04 +00:00
|
|
|
big="true"
|
|
|
|
on:click="onFollowButtonClick(event)"
|
2018-04-21 15:32:40 +00:00
|
|
|
ref:icon
|
2018-04-12 05:55:04 +00:00
|
|
|
/>
|
2018-03-31 23:51:18 +00:00
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.account-profile-follow {
|
|
|
|
grid-area: follow;
|
|
|
|
align-self: flex-start;
|
2018-04-12 05:55:04 +00:00
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
.account-profile-follow.shown {
|
|
|
|
display: block;
|
2018-03-31 23:51:18 +00: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'
|
2018-04-15 01:47:55 +00:00
|
|
|
import { setAccountBlocked } from '../../_actions/block'
|
2018-03-31 23:51:18 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
methods: {
|
2018-04-20 04:38:01 +00:00
|
|
|
async onFollowButtonClick (e) {
|
2018-03-31 23:51:18 +00:00
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
2018-04-19 16:37:05 +00:00
|
|
|
let {
|
|
|
|
account,
|
|
|
|
accountId,
|
|
|
|
following,
|
|
|
|
followRequested,
|
|
|
|
blocking
|
|
|
|
} = this.get()
|
2018-04-15 01:47:55 +00:00
|
|
|
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
|
2018-08-30 04:42:57 +00:00
|
|
|
this.set({ overrideFollowing: newFollowingValue })
|
2018-04-15 01:47:55 +00:00
|
|
|
}
|
2018-04-21 15:32:40 +00:00
|
|
|
if (newFollowingValue) {
|
|
|
|
this.refs.icon.animate(FOLLOW_BUTTON_ANIMATION)
|
|
|
|
}
|
2018-04-15 01:47:55 +00:00
|
|
|
await setAccountFollowed(accountId, newFollowingValue)
|
2018-04-03 16:51:34 +00:00
|
|
|
}
|
2018-03-31 23:51:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
store: () => store,
|
2018-04-30 16:57:49 +00:00
|
|
|
data: () => ({
|
|
|
|
overrideFollowing: void 0
|
|
|
|
}),
|
2018-03-31 23:51:18 +00:00
|
|
|
computed: {
|
2018-05-02 00:05:36 +00:00
|
|
|
accountId: ({ account }) => account.id,
|
|
|
|
following: ({ relationship, overrideFollowing }) => {
|
2018-04-03 16:51:34 +00:00
|
|
|
if (typeof overrideFollowing === 'boolean') {
|
|
|
|
return overrideFollowing
|
|
|
|
}
|
|
|
|
return relationship && relationship.following
|
|
|
|
},
|
2018-05-02 00:05:36 +00:00
|
|
|
blocking: ({ relationship }) => relationship && relationship.blocking,
|
2018-08-26 05:03:26 +00:00
|
|
|
followRequested: ({ relationship }) => {
|
|
|
|
return relationship && relationship.requested
|
2018-03-31 23:51:18 +00:00
|
|
|
},
|
2018-05-02 00:05:36 +00:00
|
|
|
followLabel: ({ blocking, following, followRequested }) => {
|
2018-04-15 01:47:55 +00:00
|
|
|
if (blocking) {
|
|
|
|
return 'Unblock'
|
|
|
|
} else if (following) {
|
2018-03-31 23:51:18 +00:00
|
|
|
return 'Unfollow'
|
|
|
|
} else if (followRequested) {
|
|
|
|
return 'Unfollow (follow requested)'
|
|
|
|
} else {
|
|
|
|
return 'Follow'
|
|
|
|
}
|
|
|
|
},
|
2018-05-02 00:05:36 +00:00
|
|
|
followIcon: ({ blocking, following, followRequested }) => {
|
2018-04-15 01:47:55 +00:00
|
|
|
if (blocking) {
|
|
|
|
return '#fa-unlock'
|
|
|
|
} else if (following) {
|
2018-03-31 23:51:18 +00:00
|
|
|
return '#fa-user-times'
|
|
|
|
} else if (followRequested) {
|
|
|
|
return '#fa-hourglass'
|
|
|
|
} else {
|
|
|
|
return '#fa-user-plus'
|
|
|
|
}
|
2018-04-12 05:55:04 +00:00
|
|
|
},
|
2018-05-02 00:05:36 +00:00
|
|
|
shown: ({ verifyCredentials, relationship }) => {
|
2018-04-12 05:55:04 +00:00
|
|
|
return verifyCredentials && relationship && verifyCredentials.id !== relationship.id
|
2018-03-31 23:51:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
IconButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|