fixed Home Page endless loading on 0 articles
This commit is contained in:
parent
f23ce5261c
commit
305d60fd74
|
@ -12,12 +12,13 @@
|
||||||
|
|
||||||
<h1 class="text-3xl lg:text-5xl font-light mb-3">@Localizer["Title"]</h1>
|
<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">
|
<div class="flex place-content-center h-full text-primary">
|
||||||
<span class="loading loading-spinner loading-lg"></span>
|
<span class="loading loading-spinner loading-lg"></span>
|
||||||
</div>
|
</div>
|
||||||
}
|
} else {
|
||||||
|
|
||||||
@if (Articles.FirstOrDefault() is {} featured) {
|
@if (Articles.FirstOrDefault() is {} featured) {
|
||||||
<article class="mb-6">
|
<article class="mb-6">
|
||||||
<a href="/article/@featured.Id">
|
<a href="/article/@featured.Id">
|
||||||
|
@ -46,6 +47,7 @@
|
||||||
<ArticleTile Article="article" />
|
<ArticleTile Article="article" />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
@if (HasMore) {
|
@if (HasMore) {
|
||||||
<div class="flex place-content-center">
|
<div class="flex place-content-center">
|
||||||
|
@ -59,9 +61,11 @@
|
||||||
|
|
||||||
private List<Article> Articles { get; } = [];
|
private List<Article> Articles { get; } = [];
|
||||||
private bool HasMore { get; set; }
|
private bool HasMore { get; set; }
|
||||||
|
private bool Busy { get; set; } = true;
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender) {
|
protected override async Task OnAfterRenderAsync(bool firstRender) {
|
||||||
if (firstRender) {
|
if (firstRender) {
|
||||||
|
try {
|
||||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
var now = DateTimeOffset.UtcNow;
|
var now = DateTimeOffset.UtcNow;
|
||||||
|
@ -72,12 +76,16 @@
|
||||||
var articles = await query.Take(11).ToListAsync();
|
var articles = await query.Take(11).ToListAsync();
|
||||||
HasMore = (await query.CountAsync()) > 11;
|
HasMore = (await query.CountAsync()) > 11;
|
||||||
Articles.AddRange(articles);
|
Articles.AddRange(articles);
|
||||||
|
} finally {
|
||||||
|
Busy = false;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task More() {
|
private async Task More() {
|
||||||
HasMore = false;
|
try {
|
||||||
|
Busy = HasMore = true;
|
||||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
var now = DateTimeOffset.UtcNow;
|
var now = DateTimeOffset.UtcNow;
|
||||||
|
@ -89,6 +97,9 @@
|
||||||
var articles = await query.Take(10).ToListAsync();
|
var articles = await query.Take(10).ToListAsync();
|
||||||
Articles.AddRange(articles);
|
Articles.AddRange(articles);
|
||||||
HasMore = (await query.CountAsync()) > 10;
|
HasMore = (await query.CountAsync()) > 10;
|
||||||
|
} finally {
|
||||||
|
Busy = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue