From cd9233c162b03aa7fe9eb909cbc3b48da2d31a0d Mon Sep 17 00:00:00 2001 From: Max <51083570+DRdrProfessor@users.noreply.github.com> Date: Mon, 15 May 2023 20:42:42 +0200 Subject: [PATCH] Working out treeview. --- SharpRss/Models/FeedModel.cs | 18 +-- SharpRss/RssService.cs | 1 - .../{GuideItemModel.cs => TreeItemData.cs} | 19 +-- WebSharpRSS/Settings.json | 2 +- WebSharpRSS/Shared/CategoryGuide.razor | 149 ------------------ WebSharpRSS/Shared/GuideItem.razor | 45 ------ WebSharpRSS/Shared/SideGuide.razor | 35 ++-- 7 files changed, 27 insertions(+), 242 deletions(-) rename WebSharpRSS/Models/{GuideItemModel.cs => TreeItemData.cs} (60%) delete mode 100644 WebSharpRSS/Shared/CategoryGuide.razor delete mode 100644 WebSharpRSS/Shared/GuideItem.razor diff --git a/SharpRss/Models/FeedModel.cs b/SharpRss/Models/FeedModel.cs index c9def46..d4ba1a9 100644 --- a/SharpRss/Models/FeedModel.cs +++ b/SharpRss/Models/FeedModel.cs @@ -1,4 +1,5 @@ -using CodeHollow.FeedReader; +using System.Threading.Tasks; +using CodeHollow.FeedReader; namespace SharpRss.Models { @@ -9,14 +10,9 @@ namespace SharpRss.Models _rssUrl = rssUrl; _fetchTask = FetchAsync(); } - private Task _fetchTask; + private readonly Task _fetchTask; - private async Task FetchAsync() - { - IsReady = false; - _feed = await FeedCache.GetFeed(_rssUrl); - IsReady = true; - } + public async Task FetchAsync() => _feed = await FeedCache.GetFeed(_rssUrl); private Feed? _feed; public Feed Base { @@ -25,16 +21,14 @@ namespace SharpRss.Models if (_feed == null) { if (_fetchTask.IsFaulted) - { IsFaulted = _fetchTask.IsFaulted; return new Feed(); } - if (!(_fetchTask.Status == TaskStatus.Running || _fetchTask.Status == TaskStatus.WaitingForActivation)) + { return new Feed(); } + if (_fetchTask.Status is not (TaskStatus.Running or TaskStatus.WaitingForActivation)) _fetchTask.Start(); _fetchTask.Wait(); } return _feed ?? new Feed(); } } - public bool IsFaulted { get; private set; } - public bool IsReady { get; private set; } private readonly string _rssUrl; } } diff --git a/SharpRss/RssService.cs b/SharpRss/RssService.cs index e9da302..46cecba 100644 --- a/SharpRss/RssService.cs +++ b/SharpRss/RssService.cs @@ -27,7 +27,6 @@ namespace SharpRss private static HashSet feedSet2 = new HashSet() { new FeedModel("https://journals.plos.org/plosone/feed/atom"), - new FeedModel("https://cyberciti.biz/feed"), new FeedModel("https://itsfoss.com/feed") }; diff --git a/WebSharpRSS/Models/GuideItemModel.cs b/WebSharpRSS/Models/TreeItemData.cs similarity index 60% rename from WebSharpRSS/Models/GuideItemModel.cs rename to WebSharpRSS/Models/TreeItemData.cs index ab05e5a..1f435b8 100644 --- a/WebSharpRSS/Models/GuideItemModel.cs +++ b/WebSharpRSS/Models/TreeItemData.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; +using System.Linq; using CodeHollow.FeedReader; using MudBlazor; using SharpRss.Models; @@ -5,25 +8,23 @@ using ToolQit; namespace WebSharpRSS.Models { - public class GuideItemModel + public class TreeItemData { - public GuideItemModel(CategoryModel catModel) + public TreeItemData(CategoryModel catModel) { CategoryModel = catModel; - Feeds = CategoryModel.Feeds.Where(x => !x.IsFaulted && x.Base != null).Select(x => new GuideItemModel(x)).ToHashSet(); + Feeds = CategoryModel.Feeds.Where(x => x.Base != null).Select(x => new TreeItemData(x)).ToHashSet(); Title = CategoryModel.Name; Icon = Icons.Material.Filled.RssFeed; } - public GuideItemModel(FeedModel feedModel) + public TreeItemData(FeedModel feedModel) { - if (feedModel.IsFaulted) - return; FeedModel = feedModel; Feed = FeedModel.Base; Title = Feed.Title; - string faviconAdress = Feed.Link.Remove(Feed.Link.IndexOf("http"), Feed.Link.IndexOf("://") + 3); - FaviconUrl = string.Format(Caretaker.Settings["Paths"].GetString("FaviconResolveUrl"), faviconAdress); + string faviconAddress = Feed.Link.Remove(Feed.Link.IndexOf("http", StringComparison.Ordinal), Feed.Link.IndexOf("://", StringComparison.Ordinal) + 3); + FaviconUrl = string.Format(Caretaker.Settings["Paths"].GetString("FaviconResolveUrl"), faviconAddress); } public readonly CategoryModel? CategoryModel; @@ -36,7 +37,7 @@ namespace WebSharpRSS.Models // Category public bool IsExpanded { get; set; } - public HashSet? Feeds { get; set; } + public HashSet? Feeds { get; set; } // Feed public Feed? Feed { get; set; } } diff --git a/WebSharpRSS/Settings.json b/WebSharpRSS/Settings.json index 07a6c68..2cb5c33 100644 --- a/WebSharpRSS/Settings.json +++ b/WebSharpRSS/Settings.json @@ -1,6 +1,6 @@ { "Paths": { - "FaviconResolveUrl": "https://icons.duckduckgo.com/ip3/{0}.ico", + "FaviconResolveUrl": "http://www.google.com/s2/favicons?domain={0}", "LogPath": "/home/max/GitHub/SharpRSS/WebSharpRSS/logs/log_.json" }, "SQL": { diff --git a/WebSharpRSS/Shared/CategoryGuide.razor b/WebSharpRSS/Shared/CategoryGuide.razor deleted file mode 100644 index e43774a..0000000 --- a/WebSharpRSS/Shared/CategoryGuide.razor +++ /dev/null @@ -1,149 +0,0 @@ -@using CodeHollow.FeedReader -@using SharpRss.Models -@using ToolQit -@using ToolQit.Containers -@using ToolQit.Extensions -@using WebSharpRSS.Models; - - -
- @HeaderText - @foreach (GuideItemModel guideModel in GuideItems) - { - - #if false -
-
-
- @if (guideItem.FaviconUrl != null) - { - - } - else - { - - } - -
-
- @guideItem.Title -
-
- @* Feeds *@ - @if (guideItem.IsExpanded && guideItem.Feeds != null) - { - foreach (FeedModel feed in guideItem.Feeds) - { - if (feed == null || feed.Base == null) continue; -
-
- @*@if (!guideFeed.FaviconUrl.IsNullEmptyWhiteSpace()) - { - - } - else - { - - }*@ - -
-
- @feed.Base.Title -
-
- } - } -
- #endif - } -
- -@code { - [Parameter] - public string HeaderText { get; set; } = string.Empty; - [Parameter] - public HashSet GuideItems { get; set; } = new HashSet(); - [Parameter] - public Action? CatItemClicked { get; set; } - [Parameter] - public Action? FeedItemClicked { get; set; } - - GuideItemModel? _selectedItem; - - void ItemClicked(GuideItemModel model) - { - model.IsExpanded = !model.IsExpanded; - if (_selectedItem != model) - { - if (_selectedItem != null) - _selectedItem.IsSelected = false; - _selectedItem = model; - _selectedItem.IsSelected = true; - } - if (model.Feeds != null && model.Feeds.Count >= 1) - { - if (model.CategoryModel != null) - CatItemClicked?.Invoke(model.CategoryModel); - } - else - { - if (model.FeedModel != null) - FeedItemClicked?.Invoke(model.FeedModel); - } - } -} \ No newline at end of file diff --git a/WebSharpRSS/Shared/GuideItem.razor b/WebSharpRSS/Shared/GuideItem.razor deleted file mode 100644 index 4c91366..0000000 --- a/WebSharpRSS/Shared/GuideItem.razor +++ /dev/null @@ -1,45 +0,0 @@ -@using WebSharpRSS.Models; - - -
-
-
- @if (Model.FaviconUrl != null) - { - - } - else - { - - } - -
-
- @Model.Title -
-
- @if (IsExpanded && Model.Feeds != null && !(Model.Feeds.Count <= 0)) - { - foreach (GuideItemModel item in Model.Feeds) - { -
- -
- } - } -
- -@code { - [Parameter] - public GuideItemModel Model { get; set; } - [Parameter] - public EventCallback ItemClicked { get; set; } - - public bool IsExpanded { get; set; } - - private void ItemClickedVoid() - { - IsExpanded = !IsExpanded; - ItemClicked.InvokeAsync(Model); - } -} diff --git a/WebSharpRSS/Shared/SideGuide.razor b/WebSharpRSS/Shared/SideGuide.razor index 579b624..316f8c7 100644 --- a/WebSharpRSS/Shared/SideGuide.razor +++ b/WebSharpRSS/Shared/SideGuide.razor @@ -10,36 +10,21 @@ Home - + + + + + @code { - public HashSet Categories = new HashSet(); + public HashSet Categories = new HashSet(); + private TreeItemData ActivatedItem { get; set; } + private TreeItemData SelectedItem { get; set; } protected override async void OnInitialized() { - Log.Verbose("Setting up test data"); - //Categories = _rssService.GetCategories().Result; + Log.Verbose("Loading guide data..."); HashSet cats = await _rssService.GetCategories(); - await Task.Run(() => Categories = cats.Select(x => new GuideItemModel(x)).ToHashSet()); + await Task.Run(() => Categories = cats.Select(x => new TreeItemData(x)).ToHashSet()); } - - private void Callback(MudListItem obj) - { - switch (obj.Value) - { - case CategoryModel catModel: - break; - case FeedModel feedModel: - break; - } - } - - private void CategoryClicked(CategoryModel cat) - { - } - - private void FeedClicked(FeedModel guideFeedItem) - { - } - } \ No newline at end of file