@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 (PicsFunc == null) return; 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 (PicsFunc == null) return; if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) { using (State.GetRefreshToken()){ pics = await PicsFunc(true); await InvokeAsync(StateHasChanged); } } } public void Dispose() { State.PropertyChanged -= StateChanged; State.CanRefresh = false; } }