SharpRSS/WebSharpRSS/Pages/List.razor

72 lines
2.1 KiB
Plaintext
Raw Normal View History

2023-05-26 21:54:12 +02:00
@page "/list"
@using WebSharpRSS.Models
@using SharpRss.Services
@inject IDialogService _dialogService;
2023-06-15 19:26:54 +02:00
@inject SyndicationService _syndicationService;
2023-05-26 21:54:12 +02:00
2023-07-09 19:28:36 +02:00
<title>@_title</title>
2023-05-26 21:54:12 +02:00
<div>
@if (_isLoading)
{
<div class="d-flex justify-center">
<div>
<MudProgressCircular Class="d-block" Color="Color.Primary" Indeterminate="true" Size="Size.Large"/>
<MudText Class="d-block">Loading...</MudText>
</div>
2023-05-26 21:54:12 +02:00
</div>
}
else
{
2023-06-23 19:36:58 +02:00
<SyndicationListItem Items="items"/>
2023-05-26 21:54:12 +02:00
}
</div>
@code {
[Parameter]
[SupplyParameterFromQuery(Name = "fid")]
public string? Fid
{
get => _fid;
set
{
_fid = value;
Task.Run(async () => await LoadItems());
2023-05-26 21:54:12 +02:00
}
}
private string? _fid;
[Parameter]
2023-06-10 20:27:26 +02:00
[SupplyParameterFromQuery(Name = "cid")]
public string? Cid
2023-05-26 21:54:12 +02:00
{
2023-06-10 20:27:26 +02:00
get => _cid;
2023-05-26 21:54:12 +02:00
set
{
2023-06-10 20:27:26 +02:00
_cid = value;
Task.Run(async () => await LoadItems());
2023-05-26 21:54:12 +02:00
}
}
2023-07-09 19:28:36 +02:00
private string _title { get; set; } = "List syndication - SharpRss";
2023-06-10 20:27:26 +02:00
private string? _cid;
2023-06-16 22:53:26 +02:00
HashSet<SyndicationItemData> items = new HashSet<SyndicationItemData>();
2023-05-26 21:54:12 +02:00
bool _isLoading = true;
private async Task LoadItems()
2023-05-26 21:54:12 +02:00
{
_isLoading = true;
if (Fid != null)
{
2023-06-16 22:53:26 +02:00
var fItems = await _syndicationService.GetSyndicationItemsAsync(Fid);
items = fItems.Select(x => SyndicationItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet();
2023-05-26 21:54:12 +02:00
}
2023-06-10 20:27:26 +02:00
else if (Cid != null)
2023-05-26 21:54:12 +02:00
{
var feeds = await _syndicationService.GetSyndicationsAsync(Cid == string.Empty ? null : Cid);
var feedIds = feeds.Select(x => x.EncodedUrl);
2023-06-16 22:53:26 +02:00
var feedItems = await _syndicationService.GetSyndicationItemsFromSyndicationsAsync(feedIds.ToArray());
items = feedItems.Select(x => SyndicationItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet();
2023-05-26 21:54:12 +02:00
}
_isLoading = false;
await InvokeAsync(StateHasChanged);
2023-05-26 21:54:12 +02:00
}
}