show last update

This commit is contained in:
iTob 2024-09-09 21:54:51 +02:00
parent fa6e8bf7cc
commit 12388b2c53
9 changed files with 113 additions and 38 deletions

View File

@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using RBLNews.Shared.Services;
namespace RBLNews.Maui namespace RBLNews.Maui
{ {
@ -17,6 +19,8 @@ namespace RBLNews.Maui
builder.Services.AddMauiBlazorWebView(); builder.Services.AddMauiBlazorWebView();
builder.Services.AddBlazorBootstrap(); builder.Services.AddBlazorBootstrap();
builder.Services.AddSingleton<IFeedDataService, FeedDataService>();
#if DEBUG #if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools(); builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug(); builder.Logging.AddDebug();

View File

@ -1,17 +1,15 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
<NavMenu /> <NavMenu />
<div class="page">
@* <div class="sidebar"> <div class="page">
@*<div class="sidebar">
<NavMenu /> <NavMenu />
</div> *@ </div> *@
<main> <main>
@* <div class="top-row px-4"> @* <div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a> <a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div> *@ </div> *@
<article class="content px-4"> <article class="content px-4">
@Body @Body
</article> </article>

View File

@ -1,9 +1,18 @@
<div class="top-row ps-3 navbar navbar-dark"> @using RBLNews.Shared.Services
@inject IFeedDataService feedDataService
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="">RBL News auf einen Blick!</a> <div class="row">
<div class="col-12">
<h3>RBL News auf einen Blick!</h3>
<Icon Name="IconName.InfoCircle" class="me-2"></Icon>Letztes Update @this.FeedDataService.Feeds?.LastUpdateDisplay
</div>
</div>
</div> </div>
</div> </div>
@* @*
<input type="checkbox" title="Navigation menu" class="navbar-toggler" /> <input type="checkbox" title="Navigation menu" class="navbar-toggler" />
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()"> <div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
@ -25,4 +34,11 @@
</div> </div>
</nav> </nav>
</div> </div>
*@ *@
@code {
[Inject]
private IFeedDataService FeedDataService { get; set; }
}

View File

@ -1,7 +1,11 @@
@page "/" @page "/"
@using RBLFeederCommon.Models.RssFeed @using RBLFeederCommon.Models.RssFeed
@using RBLNews.Shared.Enums @using RBLNews.Shared.Enums
@if (rssVM == null) @using RBLNews.Shared.Services
@inject IFeedDataService feedDataService
@if (this.FeedDataService.Feeds == null)
{ {
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
Lade Feeds ... Lade Feeds ...
@ -11,35 +15,46 @@
else else
{ {
<div class="row"> <div class="row">
@foreach (FeedGroupVM feedGrp in rssVM.FeedGroups) <div class="container">
{ @foreach (FeedGroupVM feedGrp in this.FeedDataService.Feeds.FeedGroups)
<h3>@feedGrp.PublishDate</h3>
@foreach (FeedVM feed in feedGrp.Feeds)
{ {
<div class="col-sm-12 col-md-9 col-lg-6"> <h4>@feedGrp.PublishDateDisplay</h4>
<Card> @foreach (FeedVM feed in feedGrp.Feeds)
<CardBody> {
<CardTitle>@feed.Title</CardTitle> <div class="col-xs-12 col-sm-12 col-md-8 col-lg-4">
<CardText>@feed.Description</CardText> <Card>
</CardBody> <CardBody>
<CardFooter> <CardTitle>@feed.Title</CardTitle>
@GetRssSourceName((RssFeedSources)@feed.Source) | @feed.PubDate <Button Color="ButtonColor.Primary" To="@feed.Link" Type="ButtonType.Link">Öffnen</Button> <CardText>@feed.Description</CardText>
</CardFooter> </CardBody>
</Card> <ul class="list-group list-group-flush">
<br /> <li class="list-group-item">
</div> @GetRssSourceName((RssFeedSources)@feed.Source) | @feed.PubDate
</li>
</ul>
<CardFooter>
<div class="row">
<Button Color="ButtonColor.Primary" Class="btn-sm align-self-end ml-auto" To="@feed.Link" Type="ButtonType.Link"><Icon Name="IconName.Link" /> Öffnen</Button>
</div>
</CardFooter>
</Card>
<br />
</div>
}
} }
} </div>
</div> </div>
} }
@code { @code {
private RssVM rssVM;
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
[Inject]
private IFeedDataService FeedDataService { get; set; }
protected async override Task OnInitializedAsync() protected async override Task OnInitializedAsync()
{ {
rssVM = await httpClient.GetFromJsonAsync<RssVM>("https://rblnews.de/api/feeds"); this.FeedDataService.LoadFeeds();
} }
private string GetRssSourceName(RssFeedSources source) private string GetRssSourceName(RssFeedSources source)

View File

@ -4,9 +4,11 @@ namespace RBLFeederCommon.Models.RssFeed;
public class FeedGroupVM public class FeedGroupVM
{ {
[JsonProperty("pubDate")] public string PublishDateDisplay { get => PublishDate.ToString("dd.MM.yyyy"); }
public DateTime PublishDate { get; set; }
[JsonProperty("news")] [JsonProperty("pubDate")]
public DateTime PublishDate { get; set; }
[JsonProperty("news")]
public IList<FeedVM> Feeds { get; set; } public IList<FeedVM> Feeds { get; set; }
} }

View File

@ -2,13 +2,15 @@
namespace RBLFeederCommon.Models.RssFeed; namespace RBLFeederCommon.Models.RssFeed;
public class RssVM public class RssVM
{ {
[JsonProperty("lastUpdate")] public string LastUpdateDisplay { get => this.LastUpdate.ToLocalTime().ToString("dd.MM.yyyy HH:mm"); }
public DateTime LastUpdate { get; set; }
[JsonProperty("lastUpdate")]
public DateTime LastUpdate { get; set; }
[JsonProperty("description")] [JsonProperty("description")]
public string Description { get; set; } public string Description { get; set; }

View File

@ -0,0 +1,30 @@
using RBLFeederCommon.Models.RssFeed;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
namespace RBLNews.Shared.Services
{
public interface IFeedDataService
{
public RssVM? Feeds { get; }
Task LoadFeeds();
}
public class FeedDataService : IFeedDataService
{
private static HttpClient httpClient = new HttpClient();
private RssVM? feeds;
public RssVM? Feeds { get => this.feeds; }
public async Task LoadFeeds()
{
feeds = await httpClient.GetFromJsonAsync<RssVM>("https://rblnews.de/api/feeds");
}
}
}

View File

@ -1,4 +1,9 @@
/*html, body { .top-row{
height: 5.1rem !important;
color: aqua;
}
/*html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
} }

View File

@ -1,3 +1,4 @@
using RBLNews.Shared.Services;
using RBLNews.Web.Components; using RBLNews.Web.Components;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -7,6 +8,8 @@ builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(); .AddInteractiveServerComponents();
builder.Services.AddBlazorBootstrap(); builder.Services.AddBlazorBootstrap();
builder.Services.AddSingleton<IFeedDataService, FeedDataService>();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.