@using MUnique.OpenMU.Web.Shared.Components.Toast @using MUnique.OpenMU.Web.Shared.Services @inject ToastService ToastService @implements IDisposable @if (this.ToastService.Toasts.Count > 0) {
@foreach (var toast in this.ToastService.Toasts) { var (iconClass, accentClass) = this.GetStyling(toast.Level); }
} @code { /// protected override void OnInitialized() { this.ToastService.StateChanged += this.OnStateChanged; } /// public void Dispose() { this.ToastService.StateChanged -= this.OnStateChanged; } private void OnStateChanged() { _ = this.InvokeAsync(this.StateHasChanged); } private Task CloseAsync(ToastInstance toast) { this.ToastService.Close(toast); return Task.CompletedTask; } private (string IconClass, string AccentClass) GetStyling(ToastLevel level) { return level switch { ToastLevel.Success => ("oi-circle-check", "text-success"), ToastLevel.Info => ("oi-info", "text-primary"), ToastLevel.Warning => ("oi-warning", "text-warning"), ToastLevel.Error => ("oi-bolt", "text-danger"), _ => ("oi-info", "text-primary"), }; } }