[frontend] VirtualScroller: Stop loading if there are no older notes (ISH-386)

This commit is contained in:
Lilian 2024-07-02 15:13:44 +02:00
parent a4b2806b2c
commit 4bf151324e
No known key found for this signature in database
2 changed files with 22 additions and 10 deletions

View file

@ -39,19 +39,25 @@ public partial class TimelineComponent : IAsyncDisposable
State.Timeline = res;
}
private async Task FetchOlder()
// Returning false means the API has no more content.
private async Task<bool> FetchOlder()
{
if (LockFetch) return;
if (LockFetch) return true;
LockFetch = true;
var pq = new PaginationQuery { Limit = 15, MaxId = State.MinId };
var res = await ApiService.Timelines.GetHomeTimeline(pq);
if (res.Count > 0)
switch (res.Count)
{
case > 0:
State.MinId = res.Last().Id;
State.Timeline.AddRange(res);
break;
case 0:
return false;
}
LockFetch = false;
return true;
}
private async Task FetchNewer()

View file

@ -39,7 +39,7 @@
@code {
[Parameter] [EditorRequired] public required List<NoteResponse> NoteResponseList { get; set; }
[Parameter] [EditorRequired] public required EventCallback ReachedEnd { get; set; }
[Parameter] [EditorRequired] public required Func<Task<bool>> ReachedEnd { get; set; }
[Parameter] [EditorRequired] public required EventCallback ReachedStart { get; set; }
private VirtualScrollerState State { get; set; } = new();
private int UpdateCount { get; set; } = 15;
@ -75,7 +75,13 @@
{
_loadingBottom = true;
StateHasChanged();
await ReachedEnd.InvokeAsync();
var moreAvailable = await ReachedEnd();
if (moreAvailable == false)
{
if (OvrscrlObsvBottom is null) throw new Exception("Tried to use observer that does not exist");
await OvrscrlObsvBottom.Disconnect();
}
_loadingBottom = false;
StateHasChanged();
}