Neighbourhood.omg.lol/Components/Pages/Now.razor

58 lines
1.6 KiB
Text
Raw Normal View History

2024-06-11 00:36:48 +00:00
@page "/now"
@implements IDisposable
@inject IJSRuntime JS
2024-06-11 00:36:48 +00:00
@inject State State
<RefreshButton></RefreshButton>
<PageHeading title="Now.garden" icon="fa-duotone fa-seedling">
<Description>Feel free to stroll through the <a href="now.garden">now.garden</a> and take a look at what people are up to.</Description>
</PageHeading>
2024-06-11 00:36:48 +00:00
<div id="now-garden" class="responsive card-grid">
@if (garden != null) {
foreach (NowData now in garden) {
2024-06-11 00:36:48 +00:00
<article class="now">
<nav>
<a class="author" href="/person/@now.Address#now">
2024-07-12 07:08:22 +00:00
<h6><i class="fa-duotone fa-seedling"></i><span>@now.Address</span></h6>
2024-06-11 00:36:48 +00:00
</a>
</nav>
<nav>
<small>@now.UpdatedRelative</small>
</nav>
</article>
}
}
<LoadingCard id="now-loading" icon="fa-duotone fa-seedling" class="now"></LoadingCard>
2024-06-11 00:36:48 +00:00
</div>
@code {
private List<NowData>? garden;
2024-06-11 00:36:48 +00:00
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
if (garden == null || garden.Count == 0) garden = await State.GetNowGarden();
State.PropertyChanged += StateChanged;
State.CanRefresh = true;
await InvokeAsync(StateHasChanged);
await JS.InvokeVoidAsync("removeElementById", "now-loading");
}
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
2024-06-24 04:52:45 +00:00
using (State.GetRefreshToken()){
garden = await State.GetNowGarden(true);
await InvokeAsync(StateHasChanged);
}
}
}
public void Dispose() {
State.PropertyChanged -= StateChanged;
State.CanRefresh = false;
}
2024-06-11 00:36:48 +00:00
}