filter buttons

This commit is contained in:
Tobias Wohlleben 2024-09-18 17:19:01 +02:00
parent 43002baa81
commit e8b3cd1e0a
4 changed files with 89 additions and 8 deletions

View File

@ -21,10 +21,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<!-- Display name --> <!-- Display name -->
<ApplicationTitle>RBLNews.Maui</ApplicationTitle> <ApplicationTitle>RBL News</ApplicationTitle>
<!-- App Identifier --> <!-- App Identifier -->
<ApplicationId>com.companyname.rblnews.maui</ApplicationId> <ApplicationId>com.wohlleben.rblnews.app</ApplicationId>
<!-- Versions --> <!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>

View File

@ -0,0 +1,38 @@
@using RBLFeederCommon.Enums
@if (ShowCount)
{
<Button Color="ButtonColor.Info" Size="ButtonSize.Small" Clicked="@OnClicked()" Outline>@Text <small>@Count</small></Button>
}
else
{
<Button Size="ButtonSize.Small">@Text</Button>
}
@code {
[Parameter]
public RssFeedSources Source { get; set; }
[Parameter]
public string Text { get; set; }
[Parameter]
public bool ShowCount { get; set; }
[Parameter]
public int Count { get; set; }
[Parameter]
public EventCallback<RssFeedSources> OnClickedCallback { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
}
private async Task OnClicked()
{
await OnClickedCallback.InvokeAsync(Source);
}
}

View File

@ -2,12 +2,13 @@
@page "/" @page "/"
@using RBLFeederCommon.Enums @using RBLFeederCommon.Enums
@using RBLFeederCommon.Models.RssFeed @using RBLFeederCommon.Models.RssFeed
@using RBLNews.Shared.Components.Controls
@using RBLNews.Shared.Services @using RBLNews.Shared.Services
@inject IFeedDataService feedDataService @inject IFeedDataService feedDataService
@inject AppLifecycleService appLifecycleService @inject AppLifecycleService appLifecycleService
@if (FeedDataService.Feeds == null) @if (FeedGroups == null)
{ {
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
Lade Feeds ...<br /><br /> Lade Feeds ...<br /><br />
@ -19,7 +20,13 @@ else
<br /> <br />
<div id="feeds-page" class="row"> <div id="feeds-page" class="row">
<div class="container"> <div class="container">
@foreach (FeedGroupVM feedGrp in this.FeedDataService.Feeds.FeedGroups) <div class="FilterButtons">
@foreach (IGrouping<int, int> sGrouping in SourceGroupings)
{
@* <BadgeWithCounter ShowCount="true" Source="(RssFeedSources)sGrouping.Key" OnClickedCallback="OnClicked" Text="@GetRssSourceName((RssFeedSources)sGrouping.Key)" Count="@sGrouping.Count()"></BadgeWithCounter> *@
}
</div>
@foreach (FeedGroupVM feedGrp in FeedGroups)
{ {
<h4><Icon Name="IconName.Calendar2Event" /> @feedGrp.PublishDate.ToLocalTime().ToString("dd.MM.yyyy")</h4> <h4><Icon Name="IconName.Calendar2Event" /> @feedGrp.PublishDate.ToLocalTime().ToString("dd.MM.yyyy")</h4>
@foreach (FeedVM feed in feedGrp.Feeds) @foreach (FeedVM feed in feedGrp.Feeds)
@ -57,6 +64,10 @@ else
[Inject] [Inject]
private AppLifecycleService AppLifecycleService { get; set; } private AppLifecycleService AppLifecycleService { get; set; }
private List<FeedGroupVM>? FeedGroups { get; set; }
private IEnumerable<IGrouping<int, int>> SourceGroupings { get; set; } = new List<IGrouping<int, int>>();
protected override void OnInitialized() protected override void OnInitialized()
{ {
AppLifecycleService.OnActivated = LoadFeeds; AppLifecycleService.OnActivated = LoadFeeds;
@ -66,7 +77,14 @@ else
private async void LoadFeeds() private async void LoadFeeds()
{ {
// Copy feed list to keep original list
await FeedDataService.LoadFeeds(); await FeedDataService.LoadFeeds();
FeedGroups = [..FeedDataService.Feeds.FeedGroups];
List<FeedGroupVM> listTmp = [.. FeedDataService.Feeds.FeedGroups];
SourceGroupings = listTmp.SelectMany(fg => fg.Feeds.Select(f => f.Source)).GroupBy(sources => sources);
StateHasChanged(); StateHasChanged();
} }
@ -91,5 +109,26 @@ else
return "?"; return "?";
} }
} }
private void OnClicked(RssFeedSources source)
{
FeedGroups = new List<FeedGroupVM>();
foreach (FeedGroupVM fg in FeedDataService.Feeds.FeedGroups)
{
List<FeedVM> feeds = fg.Feeds.Where(f => (RssFeedSources)f.Source == source).ToList();
if (feeds.Any())
{
FeedGroups.Add(new FeedGroupVM
{
Feeds = feeds,
PublishDate = fg.PublishDate
});
}
}
StateHasChanged();
}
} }

View File

@ -214,6 +214,10 @@ nav .top-row {
} }
} }
.FilterButtons {
margin: 10px;
}
#feeds-page h4, h5 { #feeds-page h4, h5 {
color: rgb(221, 7, 65) !important; color: rgb(221, 7, 65) !important;
text-transform: uppercase; text-transform: uppercase;