From 0220d3d304cbcb82b8531ff373dce1b35e93fb4f Mon Sep 17 00:00:00 2001
From: taehoon <th.dev91@gmail.com>
Date: Wed, 13 Feb 2019 14:55:02 -0500
Subject: Finally, added BlockCard

---
 src/components/block_card/block_card.vue | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 src/components/block_card/block_card.vue

(limited to 'src/components/block_card/block_card.vue')

diff --git a/src/components/block_card/block_card.vue b/src/components/block_card/block_card.vue
new file mode 100644
index 00000000..06fc67fc
--- /dev/null
+++ b/src/components/block_card/block_card.vue
@@ -0,0 +1,16 @@
+<template>
+  <basic-user-card :user="user">
+    <template slot="secondary-area">
+      <button class="btn btn-default" @click="unblockUser" :disabled="progress">
+        <template v-if="progress">
+          {{ $t('user_card.unblock_progress') }}
+        </template>
+        <template v-else>
+          {{ $t('user_card.unblock') }}
+        </template>
+      </button>
+    </template>
+  </basic-user-card>
+</template>
+
+<script src="./block_card.js"></script>
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2


From 52913d8f873dd6994988d6a928cca007a0effeaf Mon Sep 17 00:00:00 2001
From: taehoon <th.dev91@gmail.com>
Date: Wed, 13 Feb 2019 15:31:20 -0500
Subject: Complete functionality of BlockCard

---
 src/components/block_card/block_card.js       | 22 +++++++++++++++++++---
 src/components/block_card/block_card.vue      | 10 +++++++++-
 src/components/user_settings/user_settings.js |  2 +-
 src/i18n/en.json                              |  3 ++-
 src/modules/users.js                          |  8 ++++++++
 5 files changed, 39 insertions(+), 6 deletions(-)

(limited to 'src/components/block_card/block_card.vue')

diff --git a/src/components/block_card/block_card.js b/src/components/block_card/block_card.js
index 8788fb62..11fa27b4 100644
--- a/src/components/block_card/block_card.js
+++ b/src/components/block_card/block_card.js
@@ -1,11 +1,18 @@
 import BasicUserCard from '../basic_user_card/basic_user_card.vue'
 
 const BlockCard = {
-  props: ['user'],
+  props: ['userId'],
   data () {
     return {
-      progress: false,
-      updated: false
+      progress: false
+    }
+  },
+  computed: {
+    user () {
+      return this.$store.getters.userById(this.userId)
+    },
+    blocked () {
+      return this.user.statusnet_blocking
     }
   },
   components: {
@@ -14,6 +21,15 @@ const BlockCard = {
   methods: {
     unblockUser () {
       this.progress = true
+      this.$store.dispatch('unblockUser', this.user.id).then(() => {
+        this.progress = false
+      })
+    },
+    blockUser () {
+      this.progress = true
+      this.$store.dispatch('blockUser', this.user.id).then(() => {
+        this.progress = false
+      })
     }
   }
 }
diff --git a/src/components/block_card/block_card.vue b/src/components/block_card/block_card.vue
index 06fc67fc..ed7fe30b 100644
--- a/src/components/block_card/block_card.vue
+++ b/src/components/block_card/block_card.vue
@@ -1,7 +1,7 @@
 <template>
   <basic-user-card :user="user">
     <template slot="secondary-area">
-      <button class="btn btn-default" @click="unblockUser" :disabled="progress">
+      <button class="btn btn-default" @click="unblockUser" :disabled="progress" v-if="blocked">
         <template v-if="progress">
           {{ $t('user_card.unblock_progress') }}
         </template>
@@ -9,6 +9,14 @@
           {{ $t('user_card.unblock') }}
         </template>
       </button>
+      <button class="btn btn-default" @click="blockUser" :disabled="progress" v-else>
+        <template v-if="progress">
+          {{ $t('user_card.block_progress') }}
+        </template>
+        <template v-else>
+          {{ $t('user_card.block') }}
+        </template>
+      </button>
     </template>
   </basic-user-card>
 </template>
diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js
index 3bcecdf4..621dcd4b 100644
--- a/src/components/user_settings/user_settings.js
+++ b/src/components/user_settings/user_settings.js
@@ -9,7 +9,7 @@ import BlockCard from '../block_card/block_card.vue'
 import withLoadMore from '../../hocs/with_load_more/with_load_more'
 import withList from '../../hocs/with_list/with_list'
 
-const BlockList = withList(BlockCard, entry => ({ user: entry }))
+const BlockList = withList(BlockCard, entry => ({ userId: entry.id }))
 const BlockListWithLoadMore = withLoadMore(
   BlockList,
   (props, $store) => $store.dispatch('fetchBlocks'),
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 9027803d..eeb95f9c 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -368,7 +368,8 @@
     "remote_follow": "Remote follow",
     "statuses": "Statuses",
     "unblock": "Unblock",
-    "unblock_progress": "Unblocking..."
+    "unblock_progress": "Unblocking...",
+    "block_progress": "Blocking..."
   },
   "user_profile": {
     "timeline_title": "User Timeline"
diff --git a/src/modules/users.js b/src/modules/users.js
index 6ea4e0c9..ce8af68c 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -154,6 +154,14 @@ const users = {
           return blocks
         })
     },
+    blockUser (store, id) {
+      return store.rootState.api.backendInteractor.blockUser(id)
+        .then((user) => store.commit('addNewUsers', [user]))
+    },
+    unblockUser (store, id) {
+      return store.rootState.api.backendInteractor.unblockUser(id)
+        .then((user) => store.commit('addNewUsers', [user]))
+    },
     addFriends ({ rootState, commit }, fetchBy) {
       return new Promise((resolve, reject) => {
         const user = rootState.users.usersObject[fetchBy]
-- 
cgit v1.2.3-70-g09d2

