2024-06-07 04:25:21 +00:00
|
|
|
@inject IJSRuntime JS
|
2024-06-13 00:26:43 +00:00
|
|
|
@inject State State
|
2024-06-11 07:24:52 +00:00
|
|
|
|
2024-06-18 00:02:03 +00:00
|
|
|
@implements IDisposable
|
|
|
|
|
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 00:02:03 +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-18 00:02:03 +00:00
|
|
|
private int count { get; set; } = 0;
|
|
|
|
private int pageSize { get; } = 10;
|
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 00:02:03 +00:00
|
|
|
State.PropertyChanged += StateChanged;
|
|
|
|
State.CanRefresh = true;
|
|
|
|
|
|
|
|
if (pics == null || pics.Count == 0) await LoadNext();
|
2024-06-13 04:46:24 +00:00
|
|
|
await JS.InvokeVoidAsync("removeElementById", "pics-loading");
|
2024-06-11 07:24:52 +00:00
|
|
|
}
|
2024-06-18 00:02:03 +00:00
|
|
|
|
|
|
|
public async Task<bool> PullUp() {
|
|
|
|
int countBefore = count;
|
|
|
|
await LoadNext();
|
|
|
|
return (count != countBefore);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task LoadNext(bool forceRefresh = false) {
|
|
|
|
if (pics == null) pics = new List<Pic>();
|
|
|
|
if (forceRefresh) {
|
|
|
|
count = 0;
|
|
|
|
pics.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
var allPics = await PicsFunc(forceRefresh);
|
|
|
|
if(allPics != null && count < allPics.Count) {
|
|
|
|
pics.AddRange(allPics.Skip(count).Take(pageSize));
|
|
|
|
count = pics.Count;
|
|
|
|
}
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
|
|
|
|
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
|
|
|
|
await LoadNext(true);
|
|
|
|
State.IsRefreshing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.PropertyName == nameof(State.AtBottom) && State.AtBottom) {
|
|
|
|
await LoadNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
State.PropertyChanged -= StateChanged;
|
|
|
|
State.CanRefresh = false;
|
|
|
|
}
|
2024-06-11 07:24:52 +00:00
|
|
|
}
|