From 4bf151324eb72b5ebf19765b98eb174ff67699e9 Mon Sep 17 00:00:00 2001 From: Lilian Date: Tue, 2 Jul 2024 15:13:44 +0200 Subject: [PATCH] [frontend] VirtualScroller: Stop loading if there are no older notes (ISH-386) --- .../Components/TimelineComponent.razor.cs | 16 +++++++++++----- .../Components/VirtualScroller.razor | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Iceshrimp.Frontend/Components/TimelineComponent.razor.cs b/Iceshrimp.Frontend/Components/TimelineComponent.razor.cs index b0d5cba0..bf87833a 100644 --- a/Iceshrimp.Frontend/Components/TimelineComponent.razor.cs +++ b/Iceshrimp.Frontend/Components/TimelineComponent.razor.cs @@ -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 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() diff --git a/Iceshrimp.Frontend/Components/VirtualScroller.razor b/Iceshrimp.Frontend/Components/VirtualScroller.razor index 7c72a92c..2857557e 100644 --- a/Iceshrimp.Frontend/Components/VirtualScroller.razor +++ b/Iceshrimp.Frontend/Components/VirtualScroller.razor @@ -39,7 +39,7 @@ @code { [Parameter] [EditorRequired] public required List NoteResponseList { get; set; } - [Parameter] [EditorRequired] public required EventCallback ReachedEnd { get; set; } + [Parameter] [EditorRequired] public required Func> 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(); }