@using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Frontend.Localization @using Microsoft.Extensions.Localization @using Iceshrimp.Assets.PhosphorIcons @inject GlobalComponentSvc GlobalComponentSvc; @inject IJSRuntime Js; @inject IStringLocalizer Loc;
@if (Waiting) { } else { @Text @if (MultiLine) { } else { }
}
@code { private ElementReference Dialog { get; set; } private IJSObjectReference _module = null!; private EventCallback Action { get; set; } private string Text { get; set; } = ""; private string Placeholder { get; set; } = ""; private bool Required { get; set; } private bool MultiLine { get; set; } private string? ButtonText { get; set; } private string Input { get; set; } = ""; private bool Waiting { get; set; } private async Task CloseDialog() { await _module.InvokeVoidAsync("closeDialog", Dialog); } public async Task Prompt(EventCallback action, string text, string placeholder, string? defaultValue, bool allowEmpty = false, bool multiLine = false, string? buttonText = null) { Action = action; Text = text; Placeholder = placeholder; Required = !allowEmpty; MultiLine = multiLine; ButtonText = buttonText; Input = defaultValue ?? ""; Waiting = false; StateHasChanged(); await _module.InvokeVoidAsync("openDialog", Dialog); } private async Task ConfirmAction() { Waiting = true; await Action.InvokeAsync(MultiLine ? Input.ReplaceLineEndings("\n").Trim() : Input.ReplaceLineEndings(" ").Trim()); Waiting = false; await CloseDialog(); } private async Task CancelAction() { await Action.InvokeAsync(null); await CloseDialog(); } protected override async Task OnInitializedAsync() { _module = await Js.InvokeAsync("import", "./Components/PromptDialog.razor.js"); GlobalComponentSvc.PromptDialog = this; } }