@using Microsoft.JSInterop
@inject IJSRuntime JS
@code {
private TaskCompletionSource? tcs;
private string ModalId { get; } = $"modal_{Guid.NewGuid():N}";
[Parameter]
public string Title { get; set; } = "";
[Parameter]
public string Message { get; set; } = "";
[Parameter]
public string UserInput { get; set; } = "";
///
/// Shows the Bootstrap modal and waits for user input.
///
public async Task ShowAsync()
{
// Title = title;
// Message = message;
// UserInput = defaultValue;
tcs = new TaskCompletionSource();
await JS.InvokeVoidAsync("bootstrapModalHelper.show", $"#{ModalId}");
return await tcs.Task;
}
///
/// Shows the Bootstrap modal and waits for user input.
///
public async Task ShowAsync(string message, string defaultValue = "", string title = "Prompt")
{
Title = title;
Message = message;
UserInput = defaultValue;
tcs = new TaskCompletionSource();
await JS.InvokeVoidAsync("bootstrapModalHelper.show", $"#{ModalId}");
return await tcs.Task;
}
private async Task Confirm()
{
await JS.InvokeVoidAsync("bootstrapModalHelper.hide", $"#{ModalId}");
tcs?.TrySetResult(UserInput);
}
private async Task Cancel()
{
await JS.InvokeVoidAsync("bootstrapModalHelper.hide", $"#{ModalId}");
tcs?.TrySetResult(null);
}
}