@implements IDisposable @inject IJSRuntime JS @inject State State @if (Editable) { } @if(statuses != null) foreach(Status status in statuses) { } @code { [Parameter] public Func?>> StatusFunc { get; set; } [Parameter] public bool Editable { get; set; } = false; public EditStatusDialog? Dialog { get; set; } private List? statuses; protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); if (statuses == null || statuses.Count == 0) statuses = await StatusFunc(false); State.PropertyChanged += StateChanged; State.CanRefresh = true; await InvokeAsync(StateHasChanged); await JS.InvokeVoidAsync("removeElementById", "statusLoading"); } private async void StateChanged(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) { using (State.GetRefreshToken()) { statuses = await StatusFunc(true); await InvokeAsync(StateHasChanged); } } } public void Dispose() { State.PropertyChanged -= StateChanged; State.CanRefresh = false; } }