From 6cabef1b56598f3fb896f37c619dc4a8effa6858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Marseault?= <22910497+Larsluph@users.noreply.github.com> Date: Tue, 24 Jan 2023 10:53:34 +0100 Subject: [PATCH] perf: Add toasts for copy/paste success/error (#620) --- src/components/Modals/AddModal.vue | 11 ++++++++--- src/components/Torrent/TorrentRightClickMenu.vue | 8 ++++---- src/lang/en.json | 2 ++ src/lang/fr.json | 6 ++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/components/Modals/AddModal.vue b/src/components/Modals/AddModal.vue index 584cca7b..a10bf209 100644 --- a/src/components/Modals/AddModal.vue +++ b/src/components/Modals/AddModal.vue @@ -241,19 +241,24 @@ export default { startDropFile() { this.showWrapDrag = true }, - DragLeave(e) { + DragLeave() { this.showWrapDrag = false }, closeWrap() { if (this.showWrapDrag) this.showWrapDrag = false else this.close() }, - async paste() { + async paste(e) { if (navigator.clipboard && window.isSecureContext) { this.urls = await navigator.clipboard.readText() } else { - this.urls = document.execCommand('paste') + e.target.focus() + if (!document.execCommand('paste')) { + this.$toast.error(this.$i18n.t("toast.pasteNotSupported").toString()) + return + } } + this.$toast.success(this.$i18n.t("toast.pasteSuccess").toString()) }, submit() { if (this.files.length || this.urls) { diff --git a/src/components/Torrent/TorrentRightClickMenu.vue b/src/components/Torrent/TorrentRightClickMenu.vue index 367cdbd7..34910732 100644 --- a/src/components/Torrent/TorrentRightClickMenu.vue +++ b/src/components/Torrent/TorrentRightClickMenu.vue @@ -432,13 +432,13 @@ export default { textArea.style.opacity = '0' document.body.appendChild(textArea) textArea.select() - try { - document.execCommand('copy') - } catch (err) { - console.error('Unable to copy to clipboard', err) + if (!document.execCommand('copy')) { + this.$toast.error(this.$i18n.t("toast.copyNotSupported").toString()) + return } document.body.removeChild(textArea) } + this.$toast.success(this.$i18n.t("toast.copySuccess").toString()) } } } diff --git a/src/lang/en.json b/src/lang/en.json index db1d7698..90aa3e10 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -461,7 +461,9 @@ "ruleSaved": "Rule saved!", "renameFileFailed": "Unable to rename file", "renameFolderFailed": "Unable to rename file", + "copySuccess": "Text copied!", "copyNotSupported": "Unable to copy, clipboard API unavailable on this browser", + "pasteSuccess": "Text pasted!", "pasteNotSupported": "Unable to paste, clipboard API unavailable on this browser" }, "rightClick": { diff --git a/src/lang/fr.json b/src/lang/fr.json index bedf3399..27a2a974 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -450,8 +450,10 @@ "ruleSaved": "Règle enregistrée !", "renameFileFailed": "Impossible de renommer le fichier", "renameFolderFailed": "Impossible de renommer le dossier", - "copyNotSupported": "Impossible de copier, clipboard API indisponible dans ce navigateur", - "pasteNotSupported": "Impossible de coller, clipboard API indisponible dans ce navigateur" + "copySuccess": "Texte copié!", + "copyNotSupported": "Impossible de copier, Clipboard API indisponible dans ce navigateur", + "pasteSuccess": "Texte collé!", + "pasteNotSupported": "Impossible de coller, Clipboard API indisponible dans ce navigateur" }, "rightClick": { "resume": "Reprendre",