@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
}
@code { private ElementReference Dialog { get; set; } private IJSObjectReference _module = null!; private EventCallback Action { get; set; } private string Text { get; set; } = ""; private List<(string Label, object Value)> Options { get; set; } = []; private string? ButtonText { get; set; } private int Selected { get; set; } private bool Waiting { get; set; } private async Task CloseDialog() { await _module.InvokeVoidAsync("closeDialog", Dialog); } public async Task Select(EventCallback action, string text, List<(string, object)> options, string? buttonText = null) { Action = action; Text = text; Options = options; ButtonText = buttonText; Selected = 0; Waiting = false; StateHasChanged(); await _module.InvokeVoidAsync("openDialog", Dialog); } private async Task ConfirmAction() { Waiting = true; await Action.InvokeAsync(Options[Selected].Value); 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/SelectDialog.razor.js"); GlobalComponentSvc.SelectDialog = this; } }