fixed Home Page endless loading on 0 articles

This commit is contained in:
Mia Rose Winter 2024-01-21 17:26:22 +01:00
parent f23ce5261c
commit 305d60fd74
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -12,12 +12,13 @@
<h1 class="text-3xl lg:text-5xl font-light mb-3">@Localizer["Title"]</h1>
@if (Articles.Count < 1) {
<!-- TODO: somehow get status message -->
@if (Busy) {
<div class="flex place-content-center h-full text-primary">
<span class="loading loading-spinner loading-lg"></span>
</div>
}
} else {
@if (Articles.FirstOrDefault() is {} featured) {
<article class="mb-6">
<a href="/article/@featured.Id">
@ -46,6 +47,7 @@
<ArticleTile Article="article" />
}
</div>
}
@if (HasMore) {
<div class="flex place-content-center">
@ -59,9 +61,11 @@
private List<Article> Articles { get; } = [];
private bool HasMore { get; set; }
private bool Busy { get; set; } = true;
protected override async Task OnAfterRenderAsync(bool firstRender) {
if (firstRender) {
try {
await using var context = await ContextFactory.CreateDbContextAsync();
var now = DateTimeOffset.UtcNow;
@ -72,12 +76,16 @@
var articles = await query.Take(11).ToListAsync();
HasMore = (await query.CountAsync()) > 11;
Articles.AddRange(articles);
} finally {
Busy = false;
await InvokeAsync(StateHasChanged);
}
}
}
private async Task More() {
HasMore = false;
try {
Busy = HasMore = true;
await using var context = await ContextFactory.CreateDbContextAsync();
var now = DateTimeOffset.UtcNow;
@ -89,6 +97,9 @@
var articles = await query.Take(10).ToListAsync();
Articles.AddRange(articles);
HasMore = (await query.CountAsync()) > 10;
} finally {
Busy = false;
}
}
}