using HopFrame.Web.Components.Pages; using Microsoft.AspNetCore.Components.Forms; using Microsoft.JSInterop; namespace HopFrame.Web.Plugins; public abstract class HopFramePlugin { /// /// Downloads a file using a helper js function /// /// The name of the file /// The content of the file /// The js reference for invoking the function (Injectable) protected async Task DownloadFile(string fileName, byte[] data, IJSRuntime runtime) { using var stream = new DotNetStreamReference(new MemoryStream(data)); await runtime.InvokeVoidAsync("downloadFileFromStream", fileName, stream); } protected Task UploadFile(HopFrameTablePage targetPage, IJSRuntime runtime) { var result = new TaskCompletionSource(); targetPage.OnFileUpload = files => { result.SetResult(files.First()); targetPage.OnFileUpload = null; return Task.CompletedTask; }; runtime.InvokeVoidAsync("triggerClick", targetPage.FileInputElement!.Element); return result.Task; } }