Reworked fetching of categories.

This commit is contained in:
Max 2023-06-24 10:15:51 +02:00
parent dfc9db7944
commit 3e570a40a2
3 changed files with 16 additions and 5 deletions

View File

@ -48,8 +48,6 @@ namespace SharpRss
Icon = reader["icon"].ToString(), Icon = reader["icon"].ToString(),
LastUpdated = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(reader["last_updated"].ToString())) LastUpdated = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(reader["last_updated"].ToString()))
}; };
categoryModel.Syndications = await GetSyndicationsAsync(new []{ categoryModel.Id });
//categoryModel.SyndicationCount = await dbc.ExecuteScalarAsync<int>($"SELECT COUNT(*) FROM syndication WHERE category_id=@CatId", new { CatId = categoryModel.Id });
categories.Add(categoryModel); categories.Add(categoryModel);
} }
return categories; return categories;

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Argotic.Common; using Argotic.Common;
using Argotic.Syndication; using Argotic.Syndication;
@ -29,7 +30,19 @@ namespace SharpRss.Services
public async Task<CategoryModel?> CreateCategoryAsync(CategoryModel category) => public async Task<CategoryModel?> CreateCategoryAsync(CategoryModel category) =>
await DbAccess.SetCategoryAsync(category); await DbAccess.SetCategoryAsync(category);
public async Task<HashSet<CategoryModel>> GetCategoriesAsync() => await DbAccess.GetCategoriesAsync();
public async Task<HashSet<CategoryModel>> GetCategoriesAsync()
{
HashSet<CategoryModel> categories = await DbAccess.GetCategoriesAsync();
foreach (CategoryModel catModel in categories)
{
catModel.Syndications = await DbAccess.GetSyndicationsAsync(new[] { catModel.Id });
}
return categories;
}
private async void ForEachCategories(CategoryModel x) => x.Syndications = await DbAccess.GetSyndicationsAsync(new[] { x.Id });
public async Task<bool> AddSubscriptionAsync(string url, CategoryModel? category = null) public async Task<bool> AddSubscriptionAsync(string url, CategoryModel? category = null)
{ {
var syndication = SyndicationManager.CreateSyndication(url); var syndication = SyndicationManager.CreateSyndication(url);

View File

@ -62,8 +62,8 @@
private async void ExpandedChanged(TreeItemData treeItemData) private async void ExpandedChanged(TreeItemData treeItemData)
{ {
treeItemData.Loading = true; treeItemData.Loading = true;
var groupedItems = await _syndicationService.GetFeedsAsync(treeItemData.CategoryModel?.Id); if (treeItemData.CategoryModel != null)
treeItemData.Children = ModelToTreeItem(groupedItems); treeItemData.Children = ModelToTreeItem(treeItemData.CategoryModel.Syndications);
treeItemData.IsExpanded = !treeItemData.IsExpanded; treeItemData.IsExpanded = !treeItemData.IsExpanded;
treeItemData.Loading = false; treeItemData.Loading = false;
StateHasChanged(); StateHasChanged();