Working on read ui feed item fetching

This commit is contained in:
Max Holleman 2023-05-25 15:48:56 +02:00
parent 261a2c4150
commit b0c9816524
3 changed files with 66 additions and 21 deletions

View File

@ -57,16 +57,17 @@ namespace SharpRss.Services
Log.Warning("No feed items added to feed: {FeedUrl}", feedModel.Url);
return result;
}
public async Task<HashSet<FeedModel>> GetFeedsAsync(GroupModel? group = null) => await _dbService.GetFeedsAsync(group?.Id);
public async Task<HashSet<FeedModel>> GetFeedsAsync(string? groupId = null) => await _dbService.GetFeedsAsync(groupId);
public async Task<HashSet<FeedModel>> GetUngroupedFeedsAsync() => await _dbService.GetFeedsAsync("");
public async Task<HashSet<FeedItemModel>> GetFeedItems(FeedModel feedModel)
public async Task<HashSet<FeedItemModel>> GetFeedItemsAsync(string feedId, string? groupId = null) => await GetFeedItemsFromFeedsAsync(new[] { feedId }, groupId);
public async Task<HashSet<FeedItemModel>> GetFeedItemsFromFeedsAsync(string[] feedIds, string? groupId = null)
{
var items = await _dbService.GetFeedItemsAsync(new []{ feedModel.Id ?? string.Empty });
var items = await _dbService.GetFeedItemsAsync(feedIds);
GroupModel? group = null;
if (feedModel.GroupId != null)
if (groupId != null)
{
var model = await _dbService.GetGroupsAsync(feedModel.GroupId);
var model = await _dbService.GetGroupsAsync(groupId);
if (model != null && model.Any()) group = model.FirstOrDefault();
}
// Update the items with the group data

View File

@ -1,4 +1,4 @@
@page "/read/{Id}"
@page "/read"
@using WebSharpRSS.Models;
@using ToolQit.Extensions
@using Serilog
@ -15,9 +15,9 @@
<MudText>Loading...</MudText>
</div>
}
else if (failed)
else if (faulted)
{
<MudAlert Severity="Severity.Error" Variant="Variant.Filled">Loading failed!</MudAlert>
<MudAlert Severity="Severity.Error" Variant="Variant.Filled">Could not load feeds!</MudAlert>
}
else
{
@ -48,21 +48,57 @@
@code {
[Parameter]
public string Id { get; set; }
[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;
bool failed = false;
protected override async void OnInitialized()
bool faulted = false;
private async void LoadItems()
{
if (Id.IsNullEmptyWhiteSpace())
//TODO: better group feed fetching!
faulted = false;
if (Fid != null)
{
Log.Warning("Invalid id!");
failed = true;
}
var fItems = await _rssService.GetFeedItems(new FeedModel("") { Id = Id });
var fItems = await _rssService.GetFeedItemsAsync(Fid);
items = fItems.Select(x => FeedItemData.FromModel(x)).ToHashSet();
isLoading = false;
}
else if (Gid != null)
{
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;
}
StateHasChanged();
}
protected override void OnInitialized()
{
LoadItems();
}
}

View File

@ -6,8 +6,8 @@
@using WebSharpRSS.Models;
@using ToolQit.Extensions;
@inject FeedStateContainer _stateContainer;
@inject RssService _rssService
@inject NavigationManager Navigation
<MudStack Spacing="2">
<MudTreeView Items="_guideItems" @bind-SelectedValue="SelectedItem" Hover="true">
@ -52,12 +52,20 @@
}
private void ItemClicked()
{
if (_selectedItem == null) return;
if (_selectedItem.FeedModel != null)
{
Navigation.NavigateTo($"/read?fid={_selectedItem.FeedModel.Id}");
}
else if (_selectedItem.GroupModel != null)
{
Navigation.NavigateTo($"/read?gid={_selectedItem.GroupModel.Id}");
}
}
private async void ExpandedChanged(TreeItemData treeItemData)
{
treeItemData.Loading = true;
var groupedItems = await _rssService.GetFeedsAsync(treeItemData.GroupModel);
var groupedItems = await _rssService.GetFeedsAsync(treeItemData.GroupModel?.Id);
treeItemData.Children = ModelToTreeItem(groupedItems);
treeItemData.IsExpanded = !treeItemData.IsExpanded;
treeItemData.Loading = false;