From 6d0e98a1c2c81c587b89736dbd2ac43a8c540d54 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 30 Mar 2019 05:10:57 -0400 Subject: [PATCH] make Importer component reusable --- src/components/importer/importer.js | 42 ++++++++++++++----- src/components/importer/importer.vue | 10 ++--- src/components/user_settings/user_settings.js | 8 ++++ .../user_settings/user_settings.vue | 2 +- src/i18n/en.json | 5 +++ 5 files changed, 50 insertions(+), 17 deletions(-) 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 @@
- - + +
-

{{$t('settings.follows_imported')}}

+

{{successMessage}}

-

{{$t('settings.follow_import_error')}}

+

{{errorMessage}}

@@ -20,7 +20,7 @@