@using SharpRss.Models; @using MudBlazor.Utilities @using Serilog @using SharpRss.Services @using WebSharpRSS.Models; @using ToolQit.Extensions; @inject SyndicationService _syndicationService @inject NavigationManager _navigation
@if (context.FaviconUrl == null && context.Icon != null) { } else { } @context.Title
@context.TotalItems
@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.SyndicationModel != null) { _navigation.NavigateTo($"/list?fid={_selectedItem.SyndicationModel.EncodedUrl}"); } else if (_selectedItem.CategoryModel != null) { _navigation.NavigateTo($"/list?cid={_selectedItem.CategoryModel.Id}"); } } private async void ExpandedChanged(TreeItemData treeItemData) { treeItemData.Loading = true; if (treeItemData.CategoryModel != null) treeItemData.Children = ModelToTreeItem(treeItemData.CategoryModel.Syndications); treeItemData.IsExpanded = !treeItemData.IsExpanded; treeItemData.Loading = false; StateHasChanged(); } protected override async void OnInitialized() { Log.Verbose("Loading guide data..."); HashSet items = await _syndicationService.GetCategoriesAndSyndicationsAsync(); _guideItems.UnionWith(ModelToTreeItem(items)); StateHasChanged(); Log.Verbose("Guide initialized!"); } private HashSet ModelToTreeItem(HashSet model) => model.Select(x => x is CategoryModel model ? new TreeItemData(model) : x is SyndicationModel feedModel ? new TreeItemData(feedModel) : throw new ArgumentException("Item arg is invalid!")).ToHashSet(); }