2024-06-18 01:44:18 +00:00
|
|
|
@implements IDisposable
|
|
|
|
@inject IJSRuntime JS
|
2024-06-13 00:26:43 +00:00
|
|
|
@inject State State
|
2024-06-11 07:24:52 +00:00
|
|
|
|
|
|
|
@if (Editable) {
|
2024-06-13 04:46:24 +00:00
|
|
|
<EditPicDialog @ref="Dialog" id="EditPicModal"></EditPicDialog>
|
2024-06-11 07:24:52 +00:00
|
|
|
}
|
|
|
|
|
2024-06-13 04:46:24 +00:00
|
|
|
@if (pics != null) foreach (Pic pic in pics) {
|
|
|
|
<PicCard Pic="pic" Editable="Editable" Dialog="Dialog"></PicCard>
|
|
|
|
}
|
2024-06-11 07:24:52 +00:00
|
|
|
|
2024-06-13 04:46:24 +00:00
|
|
|
<LoadingCard id="pics-loading" icon="fa-solid fa-images"></LoadingCard>
|
2024-06-05 12:41:08 +00:00
|
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
2024-06-18 01:44:18 +00:00
|
|
|
public Func<bool, Task<List<Pic>?>> PicsFunc { get; set; }
|
2024-06-07 04:25:21 +00:00
|
|
|
[Parameter]
|
|
|
|
public bool Editable { get; set; } = false;
|
2024-06-11 07:24:52 +00:00
|
|
|
|
2024-06-13 04:46:24 +00:00
|
|
|
public EditPicDialog? Dialog { get; set; }
|
2024-06-11 07:24:52 +00:00
|
|
|
|
2024-06-13 04:46:24 +00:00
|
|
|
private List<Pic>? pics;
|
2024-06-11 07:24:52 +00:00
|
|
|
|
2024-06-13 04:46:24 +00:00
|
|
|
// TODO: There is a noticable rendering delay between the pics loading and the page rendering
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
|
|
await base.OnInitializedAsync();
|
2024-06-18 01:44:18 +00:00
|
|
|
if (pics == null || pics.Count == 0) pics = await PicsFunc(false);
|
|
|
|
State.PropertyChanged += StateChanged;
|
|
|
|
State.CanRefresh = true;
|
2024-06-13 04:46:24 +00:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
await JS.InvokeVoidAsync("removeElementById", "pics-loading");
|
2024-06-11 07:24:52 +00:00
|
|
|
}
|
2024-06-18 01:44:18 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-06-11 07:24:52 +00:00
|
|
|
}
|