mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 21:04:21 +01:00
Working on read ui feed item fetching
This commit is contained in:
parent
261a2c4150
commit
b0c9816524
|
@ -57,16 +57,17 @@ namespace SharpRss.Services
|
||||||
Log.Warning("No feed items added to feed: {FeedUrl}", feedModel.Url);
|
Log.Warning("No feed items added to feed: {FeedUrl}", feedModel.Url);
|
||||||
return result;
|
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<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;
|
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();
|
if (model != null && model.Any()) group = model.FirstOrDefault();
|
||||||
}
|
}
|
||||||
// Update the items with the group data
|
// Update the items with the group data
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@page "/read/{Id}"
|
@page "/read"
|
||||||
@using WebSharpRSS.Models;
|
@using WebSharpRSS.Models;
|
||||||
@using ToolQit.Extensions
|
@using ToolQit.Extensions
|
||||||
@using Serilog
|
@using Serilog
|
||||||
|
@ -15,9 +15,9 @@
|
||||||
<MudText>Loading...</MudText>
|
<MudText>Loading...</MudText>
|
||||||
</div>
|
</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
|
else
|
||||||
{
|
{
|
||||||
|
@ -48,21 +48,57 @@
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter]
|
[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>();
|
HashSet<FeedItemData> items = new HashSet<FeedItemData>();
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
bool failed = false;
|
bool faulted = false;
|
||||||
|
private async void LoadItems()
|
||||||
protected override async void OnInitialized()
|
|
||||||
{
|
{
|
||||||
if (Id.IsNullEmptyWhiteSpace())
|
//TODO: better group feed fetching!
|
||||||
|
faulted = false;
|
||||||
|
if (Fid != null)
|
||||||
{
|
{
|
||||||
Log.Warning("Invalid id!");
|
var fItems = await _rssService.GetFeedItemsAsync(Fid);
|
||||||
failed = true;
|
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;
|
||||||
}
|
}
|
||||||
var fItems = await _rssService.GetFeedItems(new FeedModel("") { Id = Id });
|
|
||||||
items = fItems.Select(x => FeedItemData.FromModel(x)).ToHashSet();
|
|
||||||
isLoading = false;
|
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
LoadItems();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -6,8 +6,8 @@
|
||||||
@using WebSharpRSS.Models;
|
@using WebSharpRSS.Models;
|
||||||
@using ToolQit.Extensions;
|
@using ToolQit.Extensions;
|
||||||
|
|
||||||
@inject FeedStateContainer _stateContainer;
|
|
||||||
@inject RssService _rssService
|
@inject RssService _rssService
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
|
||||||
<MudStack Spacing="2">
|
<MudStack Spacing="2">
|
||||||
<MudTreeView Items="_guideItems" @bind-SelectedValue="SelectedItem" Hover="true">
|
<MudTreeView Items="_guideItems" @bind-SelectedValue="SelectedItem" Hover="true">
|
||||||
|
@ -52,12 +52,20 @@
|
||||||
}
|
}
|
||||||
private void ItemClicked()
|
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)
|
private async void ExpandedChanged(TreeItemData treeItemData)
|
||||||
{
|
{
|
||||||
treeItemData.Loading = true;
|
treeItemData.Loading = true;
|
||||||
var groupedItems = await _rssService.GetFeedsAsync(treeItemData.GroupModel);
|
var groupedItems = await _rssService.GetFeedsAsync(treeItemData.GroupModel?.Id);
|
||||||
treeItemData.Children = ModelToTreeItem(groupedItems);
|
treeItemData.Children = ModelToTreeItem(groupedItems);
|
||||||
treeItemData.IsExpanded = !treeItemData.IsExpanded;
|
treeItemData.IsExpanded = !treeItemData.IsExpanded;
|
||||||
treeItemData.Loading = false;
|
treeItemData.Loading = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user