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

49 lines
1.4 KiB
Text
Raw Normal View History

@page "/feed"
2024-06-28 07:08:12 +00:00
@implements IDisposable
@inject IJSRuntime JS
@inject State State
2024-06-28 07:08:12 +00:00
<RefreshButton></RefreshButton>
<PageHeading title="Feed" icon="fa-solid fa-list-timeline">
<Description>A feed of all the statuses and pics of the people you follow.</Description>
</PageHeading>
@if (feed != null) foreach (StatusOrPic item in feed) {
if (item.IsStatus) {
<StatusCard Status="@item.Status"></StatusCard>
}
else if (item.IsPic) {
<PicCard Pic="@item.Pic"></PicCard>
}
}
<LoadingCard id="feedLoading" icon="fa-solid fa-list-timeline"></LoadingCard>
@code {
2024-06-28 07:08:12 +00:00
private IOrderedEnumerable<StatusOrPic>? feed;
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
if (feed == null || feed.Count() == 0) feed = await State.GetFeed();
State.PropertyChanged += StateChanged;
State.CanRefresh = true;
await InvokeAsync(StateHasChanged);
await JS.InvokeVoidAsync("removeElementById", "feedLoading");
}
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
using (State.GetRefreshToken()) {
feed = await State.GetFeed(true);
await InvokeAsync(StateHasChanged);
}
}
}
2024-06-28 07:08:12 +00:00
public void Dispose() {
State.PropertyChanged -= StateChanged;
State.CanRefresh = false;
}
}