@implements IDisposable @inject IJSRuntime JS @inject State State @if (Editable) { } @if (pics != null) foreach (Pic pic in pics) { } @code { [Parameter] public Func?>> PicsFunc { get; set; } [Parameter] public bool Editable { get; set; } = false; public EditPicDialog? Dialog { get; set; } private List? pics; // TODO: There is a noticable rendering delay between the pics loading and the page rendering protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); if (pics == null || pics.Count == 0) pics = await PicsFunc(false); State.PropertyChanged += StateChanged; State.CanRefresh = true; await InvokeAsync(StateHasChanged); await JS.InvokeVoidAsync("removeElementById", "pics-loading"); } private async void StateChanged(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) { pics = await PicsFunc(true); State.IsRefreshing = false; } } public void Dispose() { State.PropertyChanged -= StateChanged; State.CanRefresh = false; } }