SharpRSS/WebSharpRSS/Pages/List.razor

71 lines
1.8 KiB
Plaintext

@page "/list"
@using WebSharpRSS.Models
@using SharpRss.Services
@inject IDialogService _dialogService;
@inject RssService _rssService;
<div>
@if (_isLoading)
{
<div class="justify-self: center">
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
<MudText>Loading...</MudText>
</div>
}
else
{
<FeedItemList Items="items"/>
}
</div>
@code {
[Parameter]
[SupplyParameterFromQuery(Name = "fid")]
public string? Fid
{
get => _fid;
set
{
_fid = value;
LoadItems();
}
}
private string? _fid;
[Parameter]
[SupplyParameterFromQuery(Name = "gid")]
public string? Gid
{
get => _gid;
set
{
_gid = value;
LoadItems();
}
}
private string? _gid;
HashSet<FeedItemData> items = new HashSet<FeedItemData>();
bool _isLoading = true;
private async void LoadItems()
{
_isLoading = true;
if (Fid != null)
{
var fItems = await _rssService.GetFeedItemsAsync(Fid);
items = fItems.Select(x => FeedItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet();
}
else if (Gid != null)
{
var feeds = await _rssService.GetFeedsAsync(Gid);
var feedIds = feeds.Select(x => x.OriginalUrl);
var feedItems = await _rssService.GetFeedItemsFromFeedsAsync(feedIds.ToArray());
items = feedItems.Select(x => FeedItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet();
}
_isLoading = false;
StateHasChanged();
}
protected override void OnInitialized()
{
LoadItems();
}
}