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
{
@ -17,6 +19,8 @@ namespace RBLNews.Maui
builder.Services.AddMauiBlazorWebView();
builder.Services.AddBlazorBootstrap();
builder.Services.AddSingleton<IFeedDataService, FeedDataService>();
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug();

View File

@ -1,17 +1,15 @@
@inherits LayoutComponentBase
<NavMenu />
<div class="page">
@* <div class="sidebar">
<div class="page">
@*<div class="sidebar">
<NavMenu />
</div> *@
<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>
</div> *@
<article class="content px-4">
@Body
</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">
<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>
@*
@*
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
@ -25,4 +34,11 @@
</div>
</nav>
</div>
*@
*@
@code {
[Inject]
private IFeedDataService FeedDataService { get; set; }
}

View File

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

View File

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

View File

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

View File

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