aboutsummaryrefslogtreecommitdiff
path: root/src/components/follow_button
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2019-09-30 20:34:51 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2019-09-30 20:36:14 +0300
commit188b6f56ed2f983d8f0fba4dc8f7327ebbee321d (patch)
treec44c03501d88a5331c4038df9ab9b73e0e7c28c7 /src/components/follow_button
parent19cb98b85fc071dccd88bcdddff75d99cd4d944d (diff)
added acccount_actions component
Diffstat (limited to 'src/components/follow_button')
-rw-r--r--src/components/follow_button/follow_button.js58
-rw-r--r--src/components/follow_button/follow_button.vue13
2 files changed, 71 insertions, 0 deletions
diff --git a/src/components/follow_button/follow_button.js b/src/components/follow_button/follow_button.js
new file mode 100644
index 00000000..9d2834ab
--- /dev/null
+++ b/src/components/follow_button/follow_button.js
@@ -0,0 +1,58 @@
+import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'
+export default {
+ props: ['user'],
+ data () {
+ return {
+ inProgress: false
+ }
+ },
+ computed: {
+ isPressed () {
+ return this.inProgress || this.user.following
+ },
+ title () {
+ if (this.inProgress || this.user.following) {
+ return 'user_card.follow_unfollow'
+ } else if (this.user.requested) {
+ return 'user_card.follow_again'
+ } else {
+ return ''
+ }
+ },
+ label () {
+ if (this.inProgress) {
+ return 'user_card.follow_progress'
+ } else if (this.user.following) {
+ return 'user_card.following'
+ } else if (this.user.requested) {
+ return 'user_card.follow_sent'
+ } else {
+ return 'user_card.follow'
+ }
+ }
+ },
+ methods: {
+ doClick () {
+ if (this.user.following) {
+ this.unfollowUser()
+ } else {
+ this.followUser()
+ }
+ },
+ followUser () {
+ const store = this.$store
+ this.inProgress = true
+ requestFollow(this.user, store).then(() => {
+ this.inProgress = false
+ })
+ },
+ unfollowUser () {
+ const store = this.$store
+ this.inProgress = true
+ requestUnfollow(this.user, store).then(() => {
+ this.inProgress = false
+ store.commit('removeStatus', { timeline: 'friends', userId: this.user.id })
+ })
+ }
+ }
+}
diff --git a/src/components/follow_button/follow_button.vue b/src/components/follow_button/follow_button.vue
new file mode 100644
index 00000000..61aa75a0
--- /dev/null
+++ b/src/components/follow_button/follow_button.vue
@@ -0,0 +1,13 @@
+<template>
+ <button
+ class="btn btn-default btn-block follow-button"
+ :class="{ pressed: isPressed }"
+ :disabled="inProgress"
+ :title="$t(title)"
+ @click="doClick"
+ >
+ {{ $t(label) }}
+ </button>
+</template>
+
+<script src="./follow_button.js"></script>