From fa6e8bf7ccc591e9b804ada932835fbf833aa806 Mon Sep 17 00:00:00 2001 From: iTob Date: Mon, 9 Sep 2024 12:21:47 +0200 Subject: [PATCH] read feeds implemented --- .../Components/Layout/MainLayout.razor | 12 ++-- .../Components/Layout/NavMenu.razor | 7 +- RBLNews.Shared/Components/Pages/Counter.razor | 24 ------- RBLNews.Shared/Components/Pages/Feeds.razor | 67 +++++++++++++++++++ RBLNews.Shared/Components/Pages/Home.razor | 5 -- RBLNews.Shared/Components/Pages/Weather.razor | 61 ----------------- RBLNews.Shared/Enums/RssFeedSourcesEnum.cs | 13 ++++ RBLNews.Shared/Models/FeedGroupVM.cs | 12 ++++ RBLNews.Shared/Models/FeedVM.cs | 27 ++++++++ RBLNews.Shared/Models/RssVM.cs | 17 +++++ RBLNews.Shared/RBLNews.Shared.csproj | 1 + 11 files changed, 148 insertions(+), 98 deletions(-) delete mode 100644 RBLNews.Shared/Components/Pages/Counter.razor create mode 100644 RBLNews.Shared/Components/Pages/Feeds.razor delete mode 100644 RBLNews.Shared/Components/Pages/Home.razor delete mode 100644 RBLNews.Shared/Components/Pages/Weather.razor create mode 100644 RBLNews.Shared/Enums/RssFeedSourcesEnum.cs create mode 100644 RBLNews.Shared/Models/FeedGroupVM.cs create mode 100644 RBLNews.Shared/Models/FeedVM.cs create mode 100644 RBLNews.Shared/Models/RssVM.cs diff --git a/RBLNews.Shared/Components/Layout/MainLayout.razor b/RBLNews.Shared/Components/Layout/MainLayout.razor index 7cd63fe..077613b 100644 --- a/RBLNews.Shared/Components/Layout/MainLayout.razor +++ b/RBLNews.Shared/Components/Layout/MainLayout.razor @@ -1,14 +1,16 @@ @inherits LayoutComponentBase +
- + + @* *@
-
+@*
About -
+
*@
@Body diff --git a/RBLNews.Shared/Components/Layout/NavMenu.razor b/RBLNews.Shared/Components/Layout/NavMenu.razor index 67081cc..b5ac7b5 100644 --- a/RBLNews.Shared/Components/Layout/NavMenu.razor +++ b/RBLNews.Shared/Components/Layout/NavMenu.razor @@ -1,9 +1,9 @@  - +@* @@ -25,3 +25,4 @@
+ *@ \ No newline at end of file diff --git a/RBLNews.Shared/Components/Pages/Counter.razor b/RBLNews.Shared/Components/Pages/Counter.razor deleted file mode 100644 index ff8a4d4..0000000 --- a/RBLNews.Shared/Components/Pages/Counter.razor +++ /dev/null @@ -1,24 +0,0 @@ -@page "/counter" - -

Counter

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} - - - - Card title - Some quick example text to build on the card title and make up the bulk of the card's content. - - - \ No newline at end of file diff --git a/RBLNews.Shared/Components/Pages/Feeds.razor b/RBLNews.Shared/Components/Pages/Feeds.razor new file mode 100644 index 0000000..1ddfb86 --- /dev/null +++ b/RBLNews.Shared/Components/Pages/Feeds.razor @@ -0,0 +1,67 @@ +@page "/" +@using RBLFeederCommon.Models.RssFeed +@using RBLNews.Shared.Enums +@if (rssVM == null) +{ +
+ Lade Feeds ... + +
+} +else +{ +
+ @foreach (FeedGroupVM feedGrp in rssVM.FeedGroups) + { +

@feedGrp.PublishDate

+ @foreach (FeedVM feed in feedGrp.Feeds) + { +
+ + + @feed.Title + @feed.Description + + + @GetRssSourceName((RssFeedSources)@feed.Source) | @feed.PubDate + + +
+
+ + } + } +
+} +@code { + private RssVM rssVM; + HttpClient httpClient = new HttpClient(); + + protected async override Task OnInitializedAsync() + { + rssVM = await httpClient.GetFromJsonAsync("https://rblnews.de/api/feeds"); + } + + private string GetRssSourceName(RssFeedSources source) + { + switch (source) + { + case RssFeedSources.RbLive: + case RssFeedSources.NitterRbLive: + return "RBLive!"; + case RssFeedSources.NitterFabrizioRomano: + return "Fabrizio Romano"; + case RssFeedSources.Lvz: + return "LVZ"; + case RssFeedSources.Kicker: + return "Kicker"; + case RssFeedSources.Bild: + return "BILD"; + case RssFeedSources.Transfermarkt: + return "Transfermarkt"; + default: + return "?"; + } + } +} + diff --git a/RBLNews.Shared/Components/Pages/Home.razor b/RBLNews.Shared/Components/Pages/Home.razor deleted file mode 100644 index 73d0d8b..0000000 --- a/RBLNews.Shared/Components/Pages/Home.razor +++ /dev/null @@ -1,5 +0,0 @@ -@page "/" - -

Hello, world!

- -Welcome to your new app. \ No newline at end of file diff --git a/RBLNews.Shared/Components/Pages/Weather.razor b/RBLNews.Shared/Components/Pages/Weather.razor deleted file mode 100644 index 472bb98..0000000 --- a/RBLNews.Shared/Components/Pages/Weather.razor +++ /dev/null @@ -1,61 +0,0 @@ -@page "/weather" - -

Weather

- -

This component demonstrates showing data.

- -@if (forecasts == null) -{ -

Loading...

-} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
-} - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - // Simulate asynchronous loading to demonstrate a loading indicator - await Task.Delay(500); - - var startDate = DateOnly.FromDateTime(DateTime.Now); - var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; - forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = summaries[Random.Shared.Next(summaries.Length)] - }).ToArray(); - } - - private class WeatherForecast - { - public DateOnly Date { get; set; } - public int TemperatureC { get; set; } - public string? Summary { get; set; } - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } -} diff --git a/RBLNews.Shared/Enums/RssFeedSourcesEnum.cs b/RBLNews.Shared/Enums/RssFeedSourcesEnum.cs new file mode 100644 index 0000000..934dc01 --- /dev/null +++ b/RBLNews.Shared/Enums/RssFeedSourcesEnum.cs @@ -0,0 +1,13 @@ +namespace RBLNews.Shared.Enums +{ + public enum RssFeedSources + { + Lvz, + Kicker, + Bild, + Transfermarkt, + NitterRbLive, + NitterFabrizioRomano, + RbLive + } +} diff --git a/RBLNews.Shared/Models/FeedGroupVM.cs b/RBLNews.Shared/Models/FeedGroupVM.cs new file mode 100644 index 0000000..195cb7f --- /dev/null +++ b/RBLNews.Shared/Models/FeedGroupVM.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace RBLFeederCommon.Models.RssFeed; + +public class FeedGroupVM +{ + [JsonProperty("pubDate")] + public DateTime PublishDate { get; set; } + + [JsonProperty("news")] + public IList Feeds { get; set; } +} \ No newline at end of file diff --git a/RBLNews.Shared/Models/FeedVM.cs b/RBLNews.Shared/Models/FeedVM.cs new file mode 100644 index 0000000..16c9d18 --- /dev/null +++ b/RBLNews.Shared/Models/FeedVM.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; + +namespace RBLFeederCommon.Models.RssFeed; + +public class FeedVM +{ + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("imgUrl")] + public string ImgUrl { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("pubDate")] + public DateTime? PubDate { get; set; } + + [JsonProperty("link")] + public string Link { get; set; } + + [JsonProperty("source")] + public int Source { get; set; } +} \ No newline at end of file diff --git a/RBLNews.Shared/Models/RssVM.cs b/RBLNews.Shared/Models/RssVM.cs new file mode 100644 index 0000000..a7757b7 --- /dev/null +++ b/RBLNews.Shared/Models/RssVM.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace RBLFeederCommon.Models.RssFeed; + +public class RssVM +{ + [JsonProperty("lastUpdate")] + public DateTime LastUpdate { get; set; } + + + [JsonProperty("description")] + public string Description { get; set; } + + + [JsonProperty("feedGroups")] + public IList FeedGroups { get; set; } = new List(); +} \ No newline at end of file diff --git a/RBLNews.Shared/RBLNews.Shared.csproj b/RBLNews.Shared/RBLNews.Shared.csproj index 1c3c99d..b0feba6 100644 --- a/RBLNews.Shared/RBLNews.Shared.csproj +++ b/RBLNews.Shared/RBLNews.Shared.csproj @@ -15,6 +15,7 @@ +