[frontend] VirtualScroller: Stop loading if there are no older notes (ISH-386)
This commit is contained in:
parent
a4b2806b2c
commit
4bf151324e
2 changed files with 22 additions and 10 deletions
|
@ -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)
|
||||
{
|
||||
State.MinId = res.Last().Id;
|
||||
State.Timeline.AddRange(res);
|
||||
case > 0:
|
||||
State.MinId = res.Last().Id;
|
||||
State.Timeline.AddRange(res);
|
||||
break;
|
||||
case 0:
|
||||
return false;
|
||||
}
|
||||
|
||||
LockFetch = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task FetchNewer()
|
||||
|
|
|
@ -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;
|
||||
|
@ -54,9 +54,9 @@
|
|||
private ElementReference _padTopRef;
|
||||
private ElementReference _padBotRef;
|
||||
private ElementReference _scroller;
|
||||
private bool _loadingTop = false;
|
||||
private bool _loadingBottom = false;
|
||||
private bool _setScroll = false;
|
||||
private bool _loadingTop = false;
|
||||
private bool _loadingBottom = false;
|
||||
private bool _setScroll = false;
|
||||
|
||||
private ElementReference Ref
|
||||
{
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue