diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2020-07-07 15:55:07 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2020-08-21 10:11:38 +0200 |
commit | aaa23c19c054e01f9f173272988b7f2635d1d3fc (patch) | |
tree | 0ff5480652f9ae06a3ffd348ab31750471412b09 /src/components/Settings | |
parent | 87615fb6549c884aa9891666748170aea27e89e5 (diff) |
Import vcf from files
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/components/Settings')
-rw-r--r-- | src/components/Settings/SettingsImportContacts.vue | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/src/components/Settings/SettingsImportContacts.vue b/src/components/Settings/SettingsImportContacts.vue index db53be5f..b399ce41 100644 --- a/src/components/Settings/SettingsImportContacts.vue +++ b/src/components/Settings/SettingsImportContacts.vue @@ -170,6 +170,20 @@ export default { return this.importState.stage !== 'default' }, }, + + async mounted() { + // Direct import check + if (this.$route.name === 'import') { + const path = this.$route.query.file + this.processLocalFile(path) + + this.$router.push({ + name: 'group', + params: { selectedGroup: t('contacts', 'All contacts') }, + }) + } + }, + methods: { /** * Process input type file change @@ -196,6 +210,27 @@ export default { reader.readAsText(file) }, + async processLocalFile(path) { + try { + // prepare cancel token for axios request + const source = CancelToken.source() + this.cancelRequest = source.cancel + + const file = await axios.get(generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) + encodePath(path), { + cancelToken: source.token, + }) + + this.$store.dispatch('changeStage', 'parsing') + this.$store.dispatch('setAddressbook', this.selectedAddressbook.displayName) + + if (file.data) { + await this.$store.dispatch('importContactsIntoAddressbook', { vcf: file.data, addressbook: this.selectedAddressbook }) + } + } catch (error) { + console.error('Something wrong happened while processing local file', error) + } + }, + toggleModal() { this.isOpened = !this.isOpened // cancel any ongoing request if closed @@ -217,22 +252,9 @@ export default { // unlikely, but let's cancel any previous request this.cancelRequest() - // prepare cancel token for axios request - const source = CancelToken.source() - this.cancelRequest = source.cancel - - // pick and retrieve file + // pick, retrieve & process file const path = await picker.pick() - const file = await axios.get(generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) + encodePath(path), { - cancelToken: source.token, - }) - - this.$store.dispatch('changeStage', 'parsing') - this.$store.dispatch('setAddressbook', this.selectedAddressbook.displayName) - - if (file.data) { - await this.$store.dispatch('importContactsIntoAddressbook', { vcf: file.data, addressbook: this.selectedAddressbook }) - } + await this.processLocalFile(path) } catch (error) { console.error('Something wrong happened while picking a file', error) } finally { |