Neighbourhood.omg.lol/Components/PicList.razor

46 lines
No EOL
1.3 KiB
Text

@implements IDisposable
@inject IJSRuntime JS
@inject State State
@if (Editable) {
<EditPicDialog @ref="Dialog" id="EditPicModal"></EditPicDialog>
}
@if (pics != null) foreach (Pic pic in pics) {
<PicCard Pic="pic" Editable="Editable" Dialog="Dialog"></PicCard>
}
<LoadingCard id="pics-loading" icon="fa-solid fa-images"></LoadingCard>
@code {
[Parameter]
public Func<bool, Task<List<Pic>?>> PicsFunc { get; set; }
[Parameter]
public bool Editable { get; set; } = false;
public EditPicDialog? Dialog { get; set; }
private List<Pic>? 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;
}
}