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

48 lines
1.4 KiB
Text

@page "/feed"
@implements IDisposable
@inject IJSRuntime JS
@inject State State
<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 {
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);
}
}
}
public void Dispose() {
State.PropertyChanged -= StateChanged;
State.CanRefresh = false;
}
}