@using SharpRss.Models; @using MudBlazor.Utilities @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 @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($"/list?fid={_selectedItem.FeedModel.Id}"); } else if (_selectedItem.GroupModel != null) { _navigation.NavigateTo($"/list?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(); }