2023-05-25 15:48:56 +02:00
|
|
|
@page "/read"
|
2023-05-24 15:51:03 +02:00
|
|
|
@using WebSharpRSS.Models;
|
2023-05-24 19:27:22 +02:00
|
|
|
@using ToolQit.Extensions
|
|
|
|
@using Serilog
|
|
|
|
@using SharpRss.Models
|
|
|
|
@using SharpRss.Services
|
|
|
|
|
|
|
|
@inject RssService _rssService;
|
2023-05-24 15:51:03 +02:00
|
|
|
|
|
|
|
<MudStack Spacing="2" Class="ml-2 mr-2">
|
|
|
|
@if (isLoading)
|
|
|
|
{
|
|
|
|
<div class="justify-self: center">
|
|
|
|
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
|
|
|
|
<MudText>Loading...</MudText>
|
|
|
|
</div>
|
|
|
|
}
|
2023-05-25 15:48:56 +02:00
|
|
|
else if (faulted)
|
2023-05-24 15:51:03 +02:00
|
|
|
{
|
2023-05-25 15:48:56 +02:00
|
|
|
<MudAlert Severity="Severity.Error" Variant="Variant.Filled">Could not load feeds!</MudAlert>
|
2023-05-24 15:51:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach (var feedItemData in items)
|
|
|
|
{
|
|
|
|
<MudItem>
|
|
|
|
<MudCard>
|
|
|
|
<MudCardContent>
|
|
|
|
<div style="justify-self: start;" class="d-flex align-center">
|
|
|
|
@*@if (feedItemData.Icon != null)
|
|
|
|
{
|
|
|
|
<MudIcon Icon="@feedItemData.Icon" Style="@($"color:{feedItemData.CategoryColorHex}")" />
|
|
|
|
}
|
|
|
|
@if (feedItemData.FaviconUrl != null)
|
|
|
|
{
|
|
|
|
<MudImage Src="@feedItemData" ObjectFit="ObjectFit.Contain" />
|
|
|
|
}*@
|
|
|
|
<MudText Class="d-inline pa-2 align-center">@feedItemData.Title</MudText>
|
|
|
|
</div>
|
|
|
|
<MudText Typo="Typo.body2">@feedItemData.Description</MudText>
|
|
|
|
<MudText Typo="Typo.overline">@feedItemData.PublishingDate.ToString()</MudText>
|
|
|
|
</MudCardContent>
|
|
|
|
</MudCard>
|
|
|
|
</MudItem>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</MudStack>
|
|
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
2023-05-25 15:48:56 +02:00
|
|
|
[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;
|
2023-05-24 15:51:03 +02:00
|
|
|
HashSet<FeedItemData> items = new HashSet<FeedItemData>();
|
|
|
|
bool isLoading = true;
|
2023-05-25 15:48:56 +02:00
|
|
|
bool faulted = false;
|
|
|
|
private async void LoadItems()
|
2023-05-24 15:51:03 +02:00
|
|
|
{
|
2023-05-25 15:48:56 +02:00
|
|
|
//TODO: better group feed fetching!
|
|
|
|
faulted = false;
|
|
|
|
if (Fid != null)
|
|
|
|
{
|
|
|
|
var fItems = await _rssService.GetFeedItemsAsync(Fid);
|
|
|
|
items = fItems.Select(x => FeedItemData.FromModel(x)).ToHashSet();
|
|
|
|
isLoading = false;
|
|
|
|
}
|
|
|
|
else if (Gid != null)
|
2023-05-24 19:27:22 +02:00
|
|
|
{
|
2023-05-25 15:48:56 +02:00
|
|
|
var feeds = await _rssService.GetFeedsAsync(Gid);
|
|
|
|
var feedids = feeds.Select(x => x.Id);
|
|
|
|
var feedItems = await _rssService.GetFeedItemsFromFeedsAsync(feedids.ToArray());
|
|
|
|
items = feedItems.Select(x => FeedItemData.FromModel(x)).ToHashSet();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
faulted = true;
|
2023-05-24 19:27:22 +02:00
|
|
|
}
|
|
|
|
StateHasChanged();
|
2023-05-24 15:51:03 +02:00
|
|
|
}
|
2023-05-25 15:48:56 +02:00
|
|
|
protected override void OnInitialized()
|
|
|
|
{
|
|
|
|
LoadItems();
|
|
|
|
}
|
2023-05-24 15:51:03 +02:00
|
|
|
}
|