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.
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
SetZoomPercent="OnSetZoomPercentAsync"
|
||||
CanDownloadPdf="@CanDownloadPdf"
|
||||
CanPrintPdf="@CanPrintPdf"
|
||||
IsDownloading="@_isDownloading"
|
||||
IsPrinting="@_isPrinting"
|
||||
DownloadPdf="OnDownloadPdfAsync"
|
||||
PrintPdf="OnPrintPdfAsync" />
|
||||
</div>
|
||||
@@ -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)
|
||||
|
||||
@@ -86,7 +86,11 @@
|
||||
</div>
|
||||
|
||||
<div class="sender-image-toolbar__group sender-image-toolbar__group--actions" role="group" aria-label="Document actions">
|
||||
<button type="button" class="sender-image-toolbar__icon-btn" title="Print" disabled="@(!CanPrintPdf)" @onclick="PrintPdfAsync">
|
||||
<button type="button"
|
||||
class="sender-image-toolbar__icon-btn @(IsPrinting ? "sender-image-toolbar__icon-btn--busy" : string.Empty)"
|
||||
title="@(IsPrinting ? "Preparing print..." : "Print")"
|
||||
disabled="@(!CanPrintPdf || IsPrinting || IsDownloading)"
|
||||
@onclick="PrintPdfAsync">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
<path d="M7 9V4H17V9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<rect x="5" y="9" width="14" height="8" rx="2" stroke="currentColor" stroke-width="2" />
|
||||
@@ -94,7 +98,11 @@
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<button type="button" class="sender-image-toolbar__icon-btn" title="Download PDF" disabled="@(!CanDownloadPdf)" @onclick="DownloadPdfAsync">
|
||||
<button type="button"
|
||||
class="sender-image-toolbar__icon-btn @(IsDownloading ? "sender-image-toolbar__icon-btn--busy" : string.Empty)"
|
||||
title="@(IsDownloading ? "Preparing download..." : "Download PDF")"
|
||||
disabled="@(!CanDownloadPdf || IsDownloading || IsPrinting)"
|
||||
@onclick="DownloadPdfAsync">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
<path d="M12 4V14" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
||||
<path d="M8 10L12 14L16 10" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
||||
@@ -153,6 +161,12 @@
|
||||
[Parameter]
|
||||
public bool CanPrintPdf { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsDownloading { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsPrinting { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback DownloadPdf { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user