From 0430fa67b610594d7ce955632c6959add94c0fb2 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 27 Nov 2023 13:05:31 -0800 Subject: [PATCH] Show temporary status message when copied to clipboard --- src/interface/desktop/chat.html | 10 +++++++++- src/khoj/interface/web/chat.html | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index 599a8505..36fc48d0 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -15,11 +15,19 @@ let chatOptions = []; function copyProgrammaticOutput(event) { // Remove the first 4 characters which are the "Copy" button + const originalCopyText = event.target.parentNode.textContent.trim().slice(0, 4); const programmaticOutput = event.target.parentNode.textContent.trim().slice(4); navigator.clipboard.writeText(programmaticOutput).then(() => { - console.log("Programmatic output copied to clipboard"); + event.target.textContent = "✅ Copied to clipboard!"; + setTimeout(() => { + event.target.textContent = originalCopyText; + }, 1000); }).catch((error) => { console.error("Error copying programmatic output to clipboard:", error); + event.target.textContent = "⛔️ Failed to copy!"; + setTimeout(() => { + event.target.textContent = originalCopyText; + }, 1000); }); } diff --git a/src/khoj/interface/web/chat.html b/src/khoj/interface/web/chat.html index 0cbd0f67..dc643bd5 100644 --- a/src/khoj/interface/web/chat.html +++ b/src/khoj/interface/web/chat.html @@ -24,11 +24,19 @@ To get started, just start typing below. You can also type / to see a list of co let chatOptions = []; function copyProgrammaticOutput(event) { // Remove the first 4 characters which are the "Copy" button + const originalCopyText = event.target.parentNode.textContent.trim().slice(0, 4); const programmaticOutput = event.target.parentNode.textContent.trim().slice(4); navigator.clipboard.writeText(programmaticOutput).then(() => { - console.log("Programmatic output copied to clipboard"); + event.target.textContent = "✅ Copied to clipboard!"; + setTimeout(() => { + event.target.textContent = originalCopyText; + }, 1000); }).catch((error) => { console.error("Error copying programmatic output to clipboard:", error); + event.target.textContent = "⛔️ Failed to copy!"; + setTimeout(() => { + event.target.textContent = originalCopyText; + }, 1000); }); }