From 562120ae48945d87a24f2248f9b16185b49159d0 Mon Sep 17 00:00:00 2001
From: taehoon <th.dev91@gmail.com>
Date: Fri, 29 Mar 2019 21:58:20 -0400
Subject: split out follow’s importer as a separate component
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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

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

diff --git a/src/components/importer/importer.vue b/src/components/importer/importer.vue
new file mode 100644
index 00000000..0fd83b7c
--- /dev/null
+++ b/src/components/importer/importer.vue
@@ -0,0 +1,19 @@
+<template>
+  <div class="importer">
+    <form>
+      <input type="file" ref="input" v-on:change="change" />
+    </form>
+    <i class="icon-spin4 animate-spin uploading" v-if="uploading"></i>
+    <button class="btn btn-default" v-else @click="submit">{{$t('general.submit')}}</button>
+    <div v-if="success">
+      <i class="icon-cross" @click="dismiss"></i>
+      <p>{{$t('settings.follows_imported')}}</p>
+    </div>
+    <div v-else-if="error">
+      <i class="icon-cross" @click="dismiss"></i>
+      <p>{{$t('settings.follow_import_error')}}</p>
+    </div>
+  </div>
+</template>
+
+<script src="./importer.js"></script>
-- 
cgit v1.2.3-70-g09d2


From 18bb209acefcdc332cba6708d9a0e163d0d04e90 Mon Sep 17 00:00:00 2001
From: taehoon <th.dev91@gmail.com>
Date: Fri, 29 Mar 2019 23:55:49 -0400
Subject: add uploading icon css

---
 src/components/importer/importer.vue | 9 +++++++++
 1 file changed, 9 insertions(+)

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

diff --git a/src/components/importer/importer.vue b/src/components/importer/importer.vue
index 0fd83b7c..d2447e1a 100644
--- a/src/components/importer/importer.vue
+++ b/src/components/importer/importer.vue
@@ -17,3 +17,12 @@
 </template>
 
 <script src="./importer.js"></script>
+
+<style lang="scss">
+.importer {
+  .uploading {
+    font-size: 1.5em;
+    margin: 0.25em;
+  }
+}
+</style>
-- 
cgit v1.2.3-70-g09d2


From 6d0e98a1c2c81c587b89736dbd2ac43a8c540d54 Mon Sep 17 00:00:00 2001
From: taehoon <th.dev91@gmail.com>
Date: Sat, 30 Mar 2019 05:10:57 -0400
Subject: make Importer component reusable

---
 src/components/importer/importer.js            | 42 +++++++++++++++++++-------
 src/components/importer/importer.vue           | 10 +++---
 src/components/user_settings/user_settings.js  |  8 +++++
 src/components/user_settings/user_settings.vue |  2 +-
 src/i18n/en.json                               |  5 +++
 5 files changed, 50 insertions(+), 17 deletions(-)

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

diff --git a/src/components/importer/importer.js b/src/components/importer/importer.js
index 44d02c93..c5f9e4d2 100644
--- a/src/components/importer/importer.js
+++ b/src/components/importer/importer.js
@@ -1,10 +1,34 @@
 const Importer = {
+  props: {
+    submitHandler: {
+      type: Function,
+      required: true
+    },
+    submitButtonLabel: {
+      type: String,
+      default () {
+        return this.$t('importer.submit')
+      }
+    },
+    successMessage: {
+      type: String,
+      default () {
+        return this.$t('importer.success')
+      }
+    },
+    errorMessage: {
+      type: String,
+      default () {
+        return this.$t('importer.error')
+      }
+    }
+  },
   data () {
     return {
       file: null,
       error: false,
       success: false,
-      uploading: false
+      submitting: false
     }
   },
   methods: {
@@ -12,16 +36,12 @@ const Importer = {
       this.file = this.$refs.input.files[0]
     },
     submit () {
-      this.uploading = true
-      this.$store.state.api.backendInteractor.followImport(this.file)
-        .then((status) => {
-          if (status) {
-            this.success = true
-          } else {
-            this.error = true
-          }
-          this.uploading = false
-        })
+      this.dismiss()
+      this.submitting = true
+      this.submitHandler(this.file)
+        .then(() => { this.success = true })
+        .catch(() => { this.error = true })
+        .finally(() => { this.submitting = false })
     },
     dismiss () {
       this.success = false
diff --git a/src/components/importer/importer.vue b/src/components/importer/importer.vue
index d2447e1a..0c5aa93d 100644
--- a/src/components/importer/importer.vue
+++ b/src/components/importer/importer.vue
@@ -3,15 +3,15 @@
     <form>
       <input type="file" ref="input" v-on:change="change" />
     </form>
-    <i class="icon-spin4 animate-spin uploading" v-if="uploading"></i>
-    <button class="btn btn-default" v-else @click="submit">{{$t('general.submit')}}</button>
+    <i class="icon-spin4 animate-spin importer-uploading" v-if="submitting"></i>
+    <button class="btn btn-default" v-else @click="submit">{{submitButtonLabel}}</button>
     <div v-if="success">
       <i class="icon-cross" @click="dismiss"></i>
-      <p>{{$t('settings.follows_imported')}}</p>
+      <p>{{successMessage}}</p>
     </div>
     <div v-else-if="error">
       <i class="icon-cross" @click="dismiss"></i>
-      <p>{{$t('settings.follow_import_error')}}</p>
+      <p>{{errorMessage}}</p>
     </div>
   </div>
 </template>
@@ -20,7 +20,7 @@
 
 <style lang="scss">
 .importer {
-  .uploading {
+  &-uploading {
     font-size: 1.5em;
     margin: 0.25em;
   }
diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js
index a213650b..32e92dc4 100644
--- a/src/components/user_settings/user_settings.js
+++ b/src/components/user_settings/user_settings.js
@@ -234,6 +234,14 @@ const UserSettings = {
         this.backgroundUploading = false
       })
     },
+    importFollows (file) {
+      return this.$store.state.api.backendInteractor.followImport(file)
+        .then((status) => {
+          if (!status) {
+            throw new Error('failed')
+          }
+        })
+    },
     /* This function takes an Array of Users
      * and outputs a file with all the addresses for the user to download
      */
diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue
index fb91e269..fc40bdc0 100644
--- a/src/components/user_settings/user_settings.vue
+++ b/src/components/user_settings/user_settings.vue
@@ -171,7 +171,7 @@
           <div class="setting-item">
             <h2>{{$t('settings.follow_import')}}</h2>
             <p>{{$t('settings.import_followers_from_a_csv_file')}}</p>
-            <Importer />
+            <Importer :submitHandler="importFollows" :successMessage="$t('settings.follows_imported')" :errorMessage="$t('settings.follow_import_error')" />
           </div>
           <div class="setting-item" v-if="enableFollowsExport">
             <h2>{{$t('settings.follow_export')}}</h2>
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 711e8d31..34d252b2 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -31,6 +31,11 @@
     "save_without_cropping": "Save without cropping",
     "cancel": "Cancel"
   },
+  "importer": {
+    "submit": "Submit",
+    "success": "Imported successfully.",
+    "error": "An error occured while importing this file."
+  },
   "login": {
     "login": "Log in",
     "description": "Log in with OAuth",
-- 
cgit v1.2.3-70-g09d2

