From 8244971026ffefb962e235a79c5cb219163bead9 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Wed, 12 May 2021 06:39:31 +1000 Subject: [PATCH] Refactor Send 'copy link' functionality (#373) --- src/abstractions/platformUtils.service.ts | 2 +- .../components/send/add-edit.component.ts | 27 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/abstractions/platformUtils.service.ts b/src/abstractions/platformUtils.service.ts index 84918c5254f..264697aa8b7 100644 --- a/src/abstractions/platformUtils.service.ts +++ b/src/abstractions/platformUtils.service.ts @@ -29,7 +29,7 @@ export abstract class PlatformUtilsService { showPasswordDialog: (title: string, body: string, passwordValidation: (value: string) => Promise) => Promise; isDev: () => boolean; isSelfHost: () => boolean; - copyToClipboard: (text: string, options?: any) => void; + copyToClipboard: (text: string, options?: any) => void | boolean; readFromClipboard: (options?: any) => Promise; supportsBiometric: () => Promise; authenticateBiometric: () => Promise; diff --git a/src/angular/components/send/add-edit.component.ts b/src/angular/components/send/add-edit.component.ts index d32b7870071..c36a5212a51 100644 --- a/src/angular/components/send/add-edit.component.ts +++ b/src/angular/components/send/add-edit.component.ts @@ -302,8 +302,6 @@ export class AddEditComponent implements OnInit { this.formPromise = this.encryptSend(file) .then(async encSend => { const uploadPromise = this.sendService.saveWithServer(encSend); - let inactive = false; - setTimeout(() => inactive = true, 4500); await uploadPromise; if (this.send.id == null) { this.send.id = encSend[0].id; @@ -312,9 +310,17 @@ export class AddEditComponent implements OnInit { this.send.accessId = encSend[0].accessId; } this.onSavedSend.emit(this.send); - await this.showSuccessMessage(inactive); - if (this.copyLink) { - this.copyLinkToClipboard(this.link); + if (this.copyLink && this.link != null) { + const copySuccess = await this.copyLinkToClipboard(this.link); + if (copySuccess ?? true) { + this.platformUtilsService.showToast('success', null, + this.i18nService.t(this.editMode ? 'editedSend' : 'createdSend')); + } else { + await this.platformUtilsService.showDialog( + this.i18nService.t(this.editMode ? 'editedSend' : 'createdSend'), null, + this.i18nService.t('ok'), null, 'success', null); + await this.copyLinkToClipboard(this.link); + } } }); @@ -325,11 +331,6 @@ export class AddEditComponent implements OnInit { return false; } - async showSuccessMessage(inactive: boolean) { - this.platformUtilsService.showToast('success', null, - this.i18nService.t(this.editMode ? 'editedSend' : 'createdSend')); - } - clearExpiration() { this.expirationDate = null; this.expirationDateFallback = null; @@ -337,10 +338,8 @@ export class AddEditComponent implements OnInit { this.safariExpirationTime = null; } - copyLinkToClipboard(link: string) { - if (link != null) { - this.platformUtilsService.copyToClipboard(link); - } + async copyLinkToClipboard(link: string): Promise { + return Promise.resolve(this.platformUtilsService.copyToClipboard(link)); } async delete(): Promise {