From e7c4c4543472a24347d8c4df242e18d76e3e4667 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Tue, 20 May 2025 10:48:31 +0200 Subject: [PATCH] Add clipboard copy feature for messages This update introduces a new feature that allows users to copy messages to the clipboard. A boolean variable `isCopied` tracks the copy action status, and the button now shows a check icon upon successful copy, reverting after 1.5 seconds. A null check is also added in the `CopyToClipboardAsync` method to enhance error handling. --- .../Components/Pages/Ask.razor | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/SqlDatabaseVectorSearch/Components/Pages/Ask.razor b/SqlDatabaseVectorSearch/Components/Pages/Ask.razor index f67d29d..cb308f0 100644 --- a/SqlDatabaseVectorSearch/Components/Pages/Ask.razor +++ b/SqlDatabaseVectorSearch/Components/Pages/Ask.razor @@ -60,7 +60,14 @@
@@ -109,6 +116,7 @@ private Guid conversationId = Guid.NewGuid(); private bool isAsking = false; + private bool isCopied = false; protected override async Task OnAfterRenderAsync(bool firstRender) { @@ -204,7 +212,18 @@ private async Task CopyToClipboardAsync(string text) { + if (text is null) + return; + await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text); + + isCopied = true; + StateHasChanged(); + + await Task.Delay(1500); // Mostra il segno di spunta per 1.5 secondi + + isCopied = false; + StateHasChanged(); } private static string FormatTokenUsage(TokenUsageResponse? tokenUsageResponse)