using Microsoft.AspNetCore.Components; using System.Collections.Generic; using System.Threading.Tasks; namespace JobsJobsJobs.Client.Shared { public partial class Loading : ComponentBase { /// /// The delegate to call to load the data for this page /// [Parameter] public EventCallback> OnLoad { get; set; } /// /// The message to display when the page is loading (optional) /// [Parameter] public MarkupString Message { get; set; } = new MarkupString("Loading…"); /// /// The content to be displayed once the data has been loaded /// [Parameter] public RenderFragment ChildContent { get; set; } = default!; /// /// Error messages that may arise from the data loading delegate /// private ICollection ErrorMessages { get; set; } = new List(); /// /// Whether we are currently loading data /// private bool IsLoading { get; set; } = true; protected override async Task OnInitializedAsync() { if (OnLoad.HasDelegate) { try { await OnLoad.InvokeAsync(ErrorMessages); } finally { IsLoading = false; } } else { IsLoading = false; } } } }