mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 12:54:20 +01:00
Implementing treeview for feeds & categories.
This commit is contained in:
parent
cd9233c162
commit
cfd955187b
|
@ -43,7 +43,10 @@ namespace SharpRss
|
|||
|
||||
public async Task<HashSet<FeedModel>> GetAllFeeds()
|
||||
{
|
||||
return new HashSet<FeedModel>();
|
||||
HashSet<FeedModel> fSet = new HashSet<FeedModel>();
|
||||
fSet.UnionWith(feedSet);
|
||||
fSet.UnionWith(feedSet2);
|
||||
return fSet;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,11 +34,31 @@ namespace WebSharpRSS.Models
|
|||
public bool IsSelected { get; set; }
|
||||
public string? Icon { get; set; }
|
||||
public string? FaviconUrl { get; set; }
|
||||
|
||||
|
||||
// Category
|
||||
public bool HasChild => Feeds != null;
|
||||
public bool IsExpanded { get; set; }
|
||||
public HashSet<TreeItemData>? Feeds { get; set; }
|
||||
// Feed
|
||||
public Feed? Feed { get; set; }
|
||||
public int FeeditemCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CategoryModel != null && Feeds != null)
|
||||
{
|
||||
int feedsCount = 0;
|
||||
foreach (var item in Feeds)
|
||||
{
|
||||
if (item.Feed != null)
|
||||
feedsCount += item.FeeditemCount;
|
||||
}
|
||||
return feedsCount;
|
||||
}
|
||||
else if (Feed != null)
|
||||
return Feed.Items.Count;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
@using CodeHollow.FeedReader
|
||||
@using Serilog
|
||||
@using WebSharpRSS.Models;
|
||||
@using ToolQit.Extensions;
|
||||
|
||||
@inject RssService _rssService
|
||||
|
||||
|
@ -10,21 +11,47 @@
|
|||
<MudNavMenu>
|
||||
<MudNavLink Href="/" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
|
||||
</MudNavMenu>
|
||||
<MudDivider DividerType="DividerType.FullWidth"/>
|
||||
<MudText Typo="Typo.h5" Class="ml-5">Feeds</MudText>
|
||||
<MudTreeView Items="Categories" @bind-SelectedValue="SelectedItem" @bind-ActivatedItem="ActivatedItem" Hover="true">
|
||||
<ItemTemplate>
|
||||
<MudTreeViewItem Items="@context.Feeds" Icon="@context.Icon" Text="@context.Title"/>
|
||||
<MudTreeViewItem @bind-Expanded="@context.IsExpanded" Items="@context.Feeds">
|
||||
<Content>
|
||||
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
||||
<div style="justify-self: start;" class="d-flex align-center">
|
||||
<MudTreeViewItemToggleButton @bind-Expanded="@context.IsExpanded" Visible="@context.HasChild" />
|
||||
@if (context.FaviconUrl.IsNullEmptyWhiteSpace() && context.Icon != null)
|
||||
{
|
||||
<MudIcon Icon="@context.Icon"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudImage Src="@context.FaviconUrl" ObjectFit="ObjectFit.ScaleDown"/>
|
||||
}
|
||||
<MudText Class="ml-2">@context.Title</MudText>
|
||||
</div>
|
||||
<div style="justify-self: end;">
|
||||
<MudText Color="Color.Dark" Style="justify-self: end;" Typo="Typo.caption">@context.FeeditemCount</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</Content>
|
||||
</MudTreeViewItem>
|
||||
</ItemTemplate>
|
||||
</MudTreeView>
|
||||
</MudStack>
|
||||
|
||||
@code {
|
||||
public HashSet<TreeItemData> Categories = new HashSet<TreeItemData>();
|
||||
private TreeItemData ActivatedItem { get; set; }
|
||||
private TreeItemData SelectedItem { get; set; }
|
||||
private TreeItemData? ActivatedItem { get; set; }
|
||||
private TreeItemData? SelectedItem { get; set; }
|
||||
protected override async void OnInitialized()
|
||||
{
|
||||
Log.Verbose("Loading guide data...");
|
||||
|
||||
HashSet<CategoryModel> cats = await _rssService.GetCategories();
|
||||
await Task.Run(() => Categories = cats.Select(x => new TreeItemData(x)).ToHashSet());
|
||||
await Task.Run(() => Categories.UnionWith(cats.Select(x => new TreeItemData(x)).ToHashSet()));
|
||||
|
||||
Log.Verbose(" Guide initialized!");
|
||||
//await Task.Run(() => Categories = cats.Select(x => new TreeItemData(x)).ToHashSet());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user