@using Iceshrimp.Frontend.Core.Miscellaneous
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Shared.Schemas
@using Ljbc1994.Blazor.IntersectionObserver.API
@using Ljbc1994.Blazor.IntersectionObserver.Components
@inject ApiService ApiService
@if (_init)
{
@foreach (var note in Timeline)
{
}
END!
}
else
{
Loading
}
@code {
private List Timeline { get; set; } = [];
private bool _init = false;
private string? MaxId { get; set; }
private string? MinId { get; set; }
private bool LockFetch { get; set; }
private async Task Initialize()
{
var pq = new PaginationQuery() { Limit = 25 };
var res = await ApiService.Timelines.GetHomeTimeline(pq);
MaxId = res[0].Id;
MinId = res.Last().Id;
Timeline = res;
}
private async Task FetchOlder()
{
if (LockFetch) return;
LockFetch = true;
var pq = new PaginationQuery() { Limit = 5, MaxId = MinId };
var res = await ApiService.Timelines.GetHomeTimeline(pq);
if (res.Count > 0)
{
MinId = res.Last().Id;
Timeline.AddRange(res);
}
LockFetch = false;
}
private void OnEnd(IntersectionObserverEntry entry)
{
FetchOlder();
}
protected override async Task OnInitializedAsync()
{
await Initialize();
_init = true;
}
}