diff --git a/SharpRss/DbAccess.cs b/SharpRss/DbAccess.cs index 038c46f..c2dec7d 100644 --- a/SharpRss/DbAccess.cs +++ b/SharpRss/DbAccess.cs @@ -12,7 +12,6 @@ using SharpRss.Models; namespace SharpRss { - //TODO: Need rework to only get from db syndication service will handle extra data. internal static class DbAccess { private static readonly string ConnectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};"; diff --git a/SharpRss/Services/SyndicationService.cs b/SharpRss/Services/SyndicationService.cs index 42872f1..1d663a9 100644 --- a/SharpRss/Services/SyndicationService.cs +++ b/SharpRss/Services/SyndicationService.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Argotic.Common; using Argotic.Syndication; @@ -10,14 +9,14 @@ using SharpRss.Models; namespace SharpRss.Services { /// - /// Managing feeds and categories. + /// Managing syndication feeds and categories. /// public class SyndicationService { public SyndicationService() { Log.Information("Constructing SyndicationService..."); - SetupTestCategoriesAndFeedsAsync(); + Task.Run(async () => await SetupTestCategoriesAndFeedsAsync()); } public async Task> GetCategoriesAndSyndicationsAsync() @@ -59,16 +58,16 @@ namespace SharpRss.Services } catch (Exception e) { - Log.Error(e,"Error adding feed: {FeedUrl} to database!", url); + Log.Error(e,"Error adding syndication: {FeedUrl} to database!", url); } return true; } public async Task UpdateFeeds() { - Log.Information("Fetching feeds..."); - var feeds = await GetFeedsAsync(); + Log.Information("Fetching..."); + var feeds = await GetSyndicationsAsync(); } - public async Task> GetFeedsAsync(string? categoryId = null) => await DbAccess.GetSyndicationsAsync(categoryId == null ? null : new[]{ categoryId }); + public async Task> GetSyndicationsAsync(string? categoryId = null) => await DbAccess.GetSyndicationsAsync(categoryId == null ? null : new[]{ categoryId }); public async Task> GetUngroupedSyndicationsAsync() => await DbAccess.GetSyndicationsAsync(new []{""}); public async Task> GetSyndicationItemsAsync(string feedId, string? groupId = null) => await GetSyndicationItemsFromSyndicationsAsync(new[] { feedId }, groupId); public async Task> GetSyndicationItemsFromSyndicationsAsync(string[] feedIds, string? categoryId = null) @@ -98,24 +97,24 @@ namespace SharpRss.Services AtomFeed atomFeed = (AtomFeed)resource; break; default: - Log.Information("Feed implementation missing!"); + Log.Information("Syndication implementation missing!"); break; } return model; } - private GenericSyndicationFeed? CreateFeed(string url) + private GenericSyndicationFeed? CreateSyndication(string url) { Uri feedUri = new Uri(url); - Log.Verbose("Checking feed: {FeedUrl}", feedUri.ToString()); + Log.Verbose("Checking syndication: {FeedUrl}", feedUri.ToString()); if (!SyndicationDiscoveryUtility.UriExists(feedUri)) { - Log.Warning("Feed: {FeedUri} does not exists!", feedUri.ToString()); + Log.Warning("Syndication: {FeedUri} does not exists!", feedUri.ToString()); return null; } - Log.Verbose("Fetching feed: {FeedUrl}", feedUri.ToString()); + Log.Verbose("Fetching syndication: {FeedUrl}", feedUri.ToString()); return GenericSyndicationFeed.Create(new Uri(url)); } - private async void SetupTestCategoriesAndFeedsAsync() + private async Task SetupTestCategoriesAndFeedsAsync() { Log.Information("Setting up test data..."); try diff --git a/WebSharpRSS/MainLayout.razor b/WebSharpRSS/MainLayout.razor index 812780f..1e85a08 100644 --- a/WebSharpRSS/MainLayout.razor +++ b/WebSharpRSS/MainLayout.razor @@ -1,3 +1,5 @@ +@using System.Drawing +@using Color = MudBlazor.Color @inherits LayoutComponentBase @@ -27,6 +29,10 @@ + + Home + All + diff --git a/WebSharpRSS/Models/TreeItemData.cs b/WebSharpRSS/Models/TreeItemData.cs index 535e661..c18519a 100644 --- a/WebSharpRSS/Models/TreeItemData.cs +++ b/WebSharpRSS/Models/TreeItemData.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Configuration; using System.Linq; using MudBlazor; using SharpRss; diff --git a/WebSharpRSS/Pages/Index.razor b/WebSharpRSS/Pages/Index.razor index 356ef3b..1a3f6d3 100644 --- a/WebSharpRSS/Pages/Index.razor +++ b/WebSharpRSS/Pages/Index.razor @@ -1,14 +1,38 @@ @page "/" @page "/dashboard" @using WebSharpRSS.Models; +@using SharpRss.Models +@using SharpRss.Services @inject FeedStateContainer _stateContainer; +@inject SyndicationService _service; -Dashboard! - - + + @if (_loading) + { + + } + else + { + @foreach (CategoryModel category in _categories) + { + + + + } + } @code { - + bool _loading = true; + HashSet _categories = new HashSet(); + + protected override async void OnInitialized() + { + await _service.GetCategoriesAsync().ContinueWith(task => + { + _categories = task.Result; + _loading = false; + }); + } } \ No newline at end of file diff --git a/WebSharpRSS/Pages/List.razor b/WebSharpRSS/Pages/List.razor index a40652d..38fd7f5 100644 --- a/WebSharpRSS/Pages/List.razor +++ b/WebSharpRSS/Pages/List.razor @@ -8,9 +8,11 @@
@if (_isLoading) { -
- - Loading... +
+
+ + Loading... +
} else @@ -28,7 +30,7 @@ set { _fid = value; - LoadItems(); + Task.Run(async () => await LoadItems()); } } private string? _fid; @@ -40,13 +42,13 @@ set { _cid = value; - LoadItems(); + Task.Run(async () => await LoadItems()); } } private string? _cid; HashSet items = new HashSet(); bool _isLoading = true; - private async void LoadItems() + private async Task LoadItems() { _isLoading = true; if (Fid != null) @@ -56,16 +58,12 @@ } else if (Cid != null) { - var feeds = await _syndicationService.GetFeedsAsync(Cid == string.Empty ? null : Cid); + var feeds = await _syndicationService.GetSyndicationsAsync(Cid == string.Empty ? null : Cid); var feedIds = feeds.Select(x => x.EncodedUrl); var feedItems = await _syndicationService.GetSyndicationItemsFromSyndicationsAsync(feedIds.ToArray()); items = feedItems.Select(x => SyndicationItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet(); } _isLoading = false; - StateHasChanged(); - } - protected override void OnInitialized() - { - LoadItems(); + await InvokeAsync(StateHasChanged); } } \ No newline at end of file diff --git a/WebSharpRSS/Pages/_Host.cshtml b/WebSharpRSS/Pages/_Host.cshtml index 7119ff3..a162d23 100644 --- a/WebSharpRSS/Pages/_Host.cshtml +++ b/WebSharpRSS/Pages/_Host.cshtml @@ -14,7 +14,7 @@ - +
diff --git a/WebSharpRSS/Shared/DashboardCategoryItemView.razor b/WebSharpRSS/Shared/DashboardCategoryItemView.razor new file mode 100644 index 0000000..98b10a9 --- /dev/null +++ b/WebSharpRSS/Shared/DashboardCategoryItemView.razor @@ -0,0 +1,62 @@ +@using SharpRss.Models +@using SharpRss.Services +@using WebSharpRSS.Models +@using Serilog + +@inject SyndicationService _service; + + + @if (Category != null) + { +
+ + @Category.Name +
+ + @if (_isLoading) + { +
+
+ + Loading... +
+
+ } + else + { +
+ +
+ } + } + else + { + Could not load data! + } +
+ +@code { + [Parameter] + public CategoryModel? Category { get; set; } + + bool _isLoading = true; + HashSet items = new HashSet(); + + async Task LoadDataAsync() + { + if (Category == null) + { + Log.Warning("Category is null!"); + return; + } + _isLoading = true; + var syndicationIds = Category.Syndications.Select(x => x.EncodedUrl); + var syndicationItems = await _service.GetSyndicationItemsFromSyndicationsAsync(syndicationIds.ToArray()); + items = syndicationItems.Select(x => SyndicationItemData.FromModel(x)).OrderBy(x => x.PublishingDate).Reverse().ToHashSet(); + _isLoading = false; + } + protected override void OnInitialized() + { + Task.Run(async () => await LoadDataAsync()).ContinueWith(async t => await InvokeAsync(StateHasChanged)); + } +} \ No newline at end of file diff --git a/WebSharpRSS/Shared/SideGuide.razor b/WebSharpRSS/Shared/SideGuide.razor index 25be3e0..eefcdd1 100644 --- a/WebSharpRSS/Shared/SideGuide.razor +++ b/WebSharpRSS/Shared/SideGuide.razor @@ -15,7 +15,7 @@
- + @if (context.FaviconUrl == null && context.Icon != null) { @@ -71,7 +71,6 @@ protected override async void OnInitialized() { Log.Verbose("Loading guide data..."); - _guideItems.Add(new TreeItemData(new CategoryModel() { Name = "All", Icon = Icons.Material.Filled.Home, HexColor = Colors.Blue.Accent1, Id = string.Empty })); HashSet items = await _syndicationService.GetCategoriesAndSyndicationsAsync(); _guideItems.UnionWith(ModelToTreeItem(items)); diff --git a/WebSharpRSS/sharp_rss.sqlite b/WebSharpRSS/sharp_rss.sqlite index 1f3cfdc..3cdeccb 100644 Binary files a/WebSharpRSS/sharp_rss.sqlite and b/WebSharpRSS/sharp_rss.sqlite differ