From bf739c1360f6e7bb5583bcab5341065dc6c80b96 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 30 Sep 2026 17:09:33 +0200 Subject: [PATCH] Improve download/print state handling and toolbar UI Added `IsDownloading` and `IsPrinting` properties to manage state during download and print operations in `SenderPdfImageEditor.razor` and `SenderPdfImageEditorToolbar.razor`. Updated `OnDownloadPdfAsync` and `OnPrintPdfAsync` to ensure state cleanup with `finally` blocks. Enhanced toolbar buttons to reflect busy states with dynamic titles, disabled states, and a spinning animation. Updated CSS in `envelope-viewer.css` to improve layout, spacing, and responsiveness. Added hover, active, and focus-visible styles for better interactivity. Styled a new zoom slider with custom thumb and focus states. Increased maximum width of key elements to 1040px and adjusted padding/margin for better alignment. Improved focus styles for input fields and aligned actions to the right in specific scenarios. --- .../PdfEditor/SenderPdfImageEditor.razor | 60 +++++--- .../SenderPdfImageEditorToolbar.razor | 18 ++- .../wwwroot/css/envelope-viewer.css | 141 ++++++++++++++---- 3 files changed, 169 insertions(+), 50 deletions(-) diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor index f411ffcb..ee1808ae 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor @@ -26,6 +26,8 @@ SetZoomPercent="OnSetZoomPercentAsync" CanDownloadPdf="@CanDownloadPdf" CanPrintPdf="@CanPrintPdf" + IsDownloading="@_isDownloading" + IsPrinting="@_isPrinting" DownloadPdf="OnDownloadPdfAsync" PrintPdf="OnPrintPdfAsync" /> @@ -147,6 +149,8 @@ private int _currentPage = 1; private int _zoomPercent = 112; private bool _zoomOverrideInitialized; + private bool _isDownloading; + private bool _isPrinting; private const int MinZoomPercent = 50; private const int MaxZoomPercent = 300; @@ -382,33 +386,55 @@ private async Task OnDownloadPdfAsync() { - if (string.IsNullOrWhiteSpace(PdfDataUrl)) + if (string.IsNullOrWhiteSpace(PdfDataUrl) || _isDownloading || _isPrinting) return; - var fallbackName = string.IsNullOrWhiteSpace(PdfFileName) - ? "document.pdf" - : PdfFileName; + _isDownloading = true; + await InvokeAsync(StateHasChanged); - var fileName = fallbackName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase) - ? fallbackName - : $"{fallbackName}.pdf"; + try + { + var fallbackName = string.IsNullOrWhiteSpace(PdfFileName) + ? "document.pdf" + : PdfFileName; - await JSRuntime.InvokeVoidAsync( - "envelopeEditor.downloadDataUrlAsFile", - PdfDataUrl, - fileName, - "application/pdf"); + var fileName = fallbackName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase) + ? fallbackName + : $"{fallbackName}.pdf"; + + await JSRuntime.InvokeVoidAsync( + "envelopeEditor.downloadDataUrlAsFile", + PdfDataUrl, + fileName, + "application/pdf"); + } + finally + { + _isDownloading = false; + await InvokeAsync(StateHasChanged); + } } private async Task OnPrintPdfAsync() { - if (string.IsNullOrWhiteSpace(PdfDataUrl)) + if (string.IsNullOrWhiteSpace(PdfDataUrl) || _isPrinting || _isDownloading) return; - await JSRuntime.InvokeVoidAsync( - "envelopeEditor.printDataUrlPdf", - PdfDataUrl, - "application/pdf"); + _isPrinting = true; + await InvokeAsync(StateHasChanged); + + try + { + await JSRuntime.InvokeVoidAsync( + "envelopeEditor.printDataUrlPdf", + PdfDataUrl, + "application/pdf"); + } + finally + { + _isPrinting = false; + await InvokeAsync(StateHasChanged); + } } private void OnEditorMouseUp(MouseEventArgs args) diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor index f1217186..f7291ade 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor @@ -86,7 +86,11 @@
- -