From 562120ae48945d87a24f2248f9b16185b49159d0 Mon Sep 17 00:00:00 2001
From: taehoon
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.js | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 src/components/importer/importer.js
(limited to 'src/components/importer/importer.js')
diff --git a/src/components/importer/importer.js b/src/components/importer/importer.js
new file mode 100644
index 00000000..8d6c8b3f
--- /dev/null
+++ b/src/components/importer/importer.js
@@ -0,0 +1,36 @@
+const Importer = {
+ data () {
+ return {
+ file: null,
+ error: false,
+ success: false,
+ uploading: false
+ }
+ },
+ methods: {
+ change () {
+ this.file = this.$refs.input.files[0]
+ },
+ submit () {
+ this.uploading = true
+ // eslint-disable-next-line no-undef
+ const formData = new FormData()
+ formData.append('list', this.file)
+ this.$store.state.api.backendInteractor.followImport({params: formData})
+ .then((status) => {
+ if (status) {
+ this.success = true
+ } else {
+ this.error = true
+ }
+ this.uploading = false
+ })
+ },
+ dismiss () {
+ this.success = false
+ this.error = false
+ }
+ }
+}
+
+export default Importer
--
cgit v1.2.3-70-g09d2
From 903bce40c3b013ed2f2347c254ea184293b45b22 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Fri, 29 Mar 2019 23:39:24 -0400
Subject: move formData generating logic to api.service
---
src/components/importer/importer.js | 5 +----
src/services/api/api.service.js | 6 ++++--
.../backend_interactor_service/backend_interactor_service.js | 2 +-
3 files changed, 6 insertions(+), 7 deletions(-)
(limited to 'src/components/importer/importer.js')
diff --git a/src/components/importer/importer.js b/src/components/importer/importer.js
index 8d6c8b3f..44d02c93 100644
--- a/src/components/importer/importer.js
+++ b/src/components/importer/importer.js
@@ -13,10 +13,7 @@ const Importer = {
},
submit () {
this.uploading = true
- // eslint-disable-next-line no-undef
- const formData = new FormData()
- formData.append('list', this.file)
- this.$store.state.api.backendInteractor.followImport({params: formData})
+ this.$store.state.api.backendInteractor.followImport(this.file)
.then((status) => {
if (status) {
this.success = true
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 6b255e9f..3f6ffccc 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -634,9 +634,11 @@ const uploadMedia = ({formData, credentials}) => {
.then((data) => parseAttachment(data))
}
-const followImport = ({params, credentials}) => {
+const followImport = ({file, credentials}) => {
+ const formData = new FormData()
+ formData.append('list', file)
return fetch(FOLLOW_IMPORT_URL, {
- body: params,
+ body: formData,
method: 'POST',
headers: authHeaders(credentials)
})
diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js
index 75bba92b..2438c603 100644
--- a/src/services/backend_interactor_service/backend_interactor_service.js
+++ b/src/services/backend_interactor_service/backend_interactor_service.js
@@ -107,7 +107,7 @@ const backendInteractorService = (credentials) => {
const updateProfile = ({params}) => apiService.updateProfile({credentials, params})
const externalProfile = (profileUrl) => apiService.externalProfile({profileUrl, credentials})
- const followImport = ({params}) => apiService.followImport({params, credentials})
+ const followImport = (file) => apiService.followImport({file, credentials})
const deleteAccount = ({password}) => apiService.deleteAccount({credentials, password})
const changePassword = ({password, newPassword, newPasswordConfirmation}) => apiService.changePassword({credentials, password, newPassword, newPasswordConfirmation})
--
cgit v1.2.3-70-g09d2
From 6d0e98a1c2c81c587b89736dbd2ac43a8c540d54 Mon Sep 17 00:00:00 2001
From: taehoon
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.js')
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 @@