@using SharpRss.Models; @using MudBlazor.Utilities @using CodeHollow.FeedReader @using Serilog @using SharpRss.Services @using WebSharpRSS.Models; @using ToolQit.Extensions; @inject RssService _rssService @inject NavigationManager Navigation @if (context.FaviconUrl == null && context.Icon != null) { } else { } @context.Title @*@context.FeeditemCount*@ @code { private MudTheme Theme = new MudTheme(); private readonly HashSet _guideItems = new HashSet(); private TreeItemData? _selectedItem; private TreeItemData? SelectedItem { get => _selectedItem; set { _selectedItem = value; 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) { treeItemData.Loading = true; var groupedItems = await _rssService.GetFeedsAsync(treeItemData.GroupModel?.Id); treeItemData.Children = ModelToTreeItem(groupedItems); treeItemData.IsExpanded = !treeItemData.IsExpanded; treeItemData.Loading = false; StateHasChanged(); } protected override async void OnInitialized() { Log.Verbose("Loading guide data..."); HashSet items = await _rssService.GetGroupsFeedsAsync(); _guideItems.UnionWith(ModelToTreeItem(items)); StateHasChanged(); Log.Verbose("Guide initialized!"); } private HashSet ModelToTreeItem(HashSet model) => model.Select(x => x is GroupModel model ? new TreeItemData(model) : x is FeedModel feedModel ? new TreeItemData(feedModel) : throw new ArgumentException("Item arg is invalid!")).ToHashSet(); }