move filter to switch with badge
This commit is contained in:
parent
ff1ebac99a
commit
8d5a68b49b
@ -1,6 +1,7 @@
|
|||||||
@using RBLFeederCommon.Enums
|
@using RBLFeederCommon.Enums
|
||||||
|
@using RBLNews.Shared.Models
|
||||||
|
|
||||||
<Switch Class="mt-3" Value="this._filter" Label="@this.Text" ValueExpression="() => this._filter" ValueChanged="SwitchChanged" />
|
<Switch Class="mt-2" Value="this._filter" Label="@this.Text" ValueExpression="() => this._filter" ValueChanged="SwitchChanged" />
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@ -20,13 +21,17 @@
|
|||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<RssFeedSources> OnClickedCallback { get; set; }
|
public EventCallback<FilterFeedEventArg> OnFilterChanged { get; set; }
|
||||||
|
|
||||||
Task SwitchChanged(bool value)
|
Task SwitchChanged(bool value)
|
||||||
{
|
{
|
||||||
this._filter = value;
|
this._filter = value;
|
||||||
|
|
||||||
OnClickedCallback.InvokeAsync(Source);
|
OnFilterChanged.InvokeAsync(new FilterFeedEventArg
|
||||||
|
{
|
||||||
|
Source = this.Source,
|
||||||
|
Value = value
|
||||||
|
});
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
@using RBLFeederCommon.Models.RssFeed
|
@using RBLFeederCommon.Models.RssFeed
|
||||||
@using RBLNews.Shared.Services
|
@using RBLNews.Shared.Services
|
||||||
@using RBLNews.Shared.Components.Controls
|
@using RBLNews.Shared.Components.Controls
|
||||||
|
@using RBLNews.Shared.Models
|
||||||
|
|
||||||
@inject IFeedDataService feedDataService
|
@inject IFeedDataService feedDataService
|
||||||
@inject AppLifecycleService appLifecycleService
|
@inject AppLifecycleService appLifecycleService
|
||||||
@ -19,15 +20,19 @@ else
|
|||||||
<div id="feeds-page">
|
<div id="feeds-page">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<section id="filter">
|
<section id="filter">
|
||||||
|
<div class="row">
|
||||||
@foreach (IGrouping<int, int> sGrouping in SourceGroupings)
|
@foreach (IGrouping<int, int> sGrouping in SourceGroupings)
|
||||||
{
|
{
|
||||||
|
<div class="col col-lg-1">
|
||||||
<SwitchWithBadge
|
<SwitchWithBadge
|
||||||
Source="(RssFeedSources)sGrouping.Key"
|
Source="(RssFeedSources)sGrouping.Key"
|
||||||
OnClickedCallback="OnClicked"
|
OnFilterChanged="OnFilterChanged"
|
||||||
Text="@GetRssSourceName((RssFeedSources)sGrouping.Key)"
|
Text="@GetRssSourceName((RssFeedSources)sGrouping.Key)"
|
||||||
Count="@sGrouping.Count()">
|
Count="@sGrouping.Count()">
|
||||||
</SwitchWithBadge>
|
</SwitchWithBadge>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section id="feeds-list">
|
<section id="feeds-list">
|
||||||
@foreach (FeedGroupVM feedGrp in FeedGroups)
|
@foreach (FeedGroupVM feedGrp in FeedGroups)
|
||||||
@ -37,7 +42,7 @@ else
|
|||||||
</h1>
|
</h1>
|
||||||
@foreach (FeedVM feed in feedGrp.Feeds)
|
@foreach (FeedVM feed in feedGrp.Feeds)
|
||||||
{
|
{
|
||||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-4">
|
<div class="col-xs-12 col-sm-12 col-md-9 col-lg-7 col-xl-5">
|
||||||
<Card>
|
<Card>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<CardTitle>@feed.Title</CardTitle>
|
<CardTitle>@feed.Title</CardTitle>
|
||||||
@ -78,7 +83,7 @@ else
|
|||||||
|
|
||||||
private IEnumerable<IGrouping<int, int>> SourceGroupings { get; set; } = new List<IGrouping<int, int>>();
|
private IEnumerable<IGrouping<int, int>> SourceGroupings { get; set; } = new List<IGrouping<int, int>>();
|
||||||
|
|
||||||
private List<RssFeedSources> activeFilters = new List<RssFeedSources>();
|
private List<RssFeedSources> activeFeedSources = new List<RssFeedSources>();
|
||||||
|
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
@ -89,6 +94,19 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void SetFilter()
|
||||||
|
{
|
||||||
|
this.activeFeedSources.Clear();
|
||||||
|
|
||||||
|
IEnumerable<int> enumerable = this.SourceGroupings.Select(grp => grp.Key).Distinct();
|
||||||
|
|
||||||
|
foreach (int i in enumerable)
|
||||||
|
{
|
||||||
|
this.activeFeedSources.Add((RssFeedSources)i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private async void LoadFeeds()
|
private async void LoadFeeds()
|
||||||
{
|
{
|
||||||
// Copy feed list to keep original list
|
// Copy feed list to keep original list
|
||||||
@ -99,6 +117,10 @@ else
|
|||||||
|
|
||||||
SourceGroupings = listTmp.SelectMany(fg => fg.Feeds.Select(f => f.Source)).GroupBy(sources => sources);
|
SourceGroupings = listTmp.SelectMany(fg => fg.Feeds.Select(f => f.Source)).GroupBy(sources => sources);
|
||||||
|
|
||||||
|
SetFilter();
|
||||||
|
|
||||||
|
this.FilterFeeds();
|
||||||
|
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,24 +148,32 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnClicked(RssFeedSources source, bool value)
|
private void OnFilterChanged(FilterFeedEventArg eventArg)
|
||||||
{
|
{
|
||||||
if (activeFilters.Contains(source))
|
if (eventArg.Value && !this.activeFeedSources.Contains(eventArg.Source))
|
||||||
{
|
{
|
||||||
activeFilters.Remove(source);
|
activeFeedSources.Add(eventArg.Source);
|
||||||
}
|
}
|
||||||
else
|
else if (this.activeFeedSources.Contains(eventArg.Source))
|
||||||
{
|
{
|
||||||
activeFilters.Add(source);
|
activeFeedSources.Remove(eventArg.Source);
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedGroups = new List<FeedGroupVM>();
|
this.FilterFeeds();
|
||||||
foreach (FeedGroupVM fg in FeedDataService.Feeds.FeedGroups)
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void FilterFeeds()
|
||||||
{
|
{
|
||||||
List<FeedVM> feeds = fg.Feeds.Where(f => activeFilters.Contains((RssFeedSources)f.Source)).ToList();
|
this.FeedGroups = new List<FeedGroupVM>();
|
||||||
|
foreach (FeedGroupVM fg in this.FeedDataService.Feeds.FeedGroups)
|
||||||
|
{
|
||||||
|
List<FeedVM> feeds = fg.Feeds.Where(f => this.activeFeedSources.Contains((RssFeedSources)f.Source)).ToList();
|
||||||
if (feeds.Any())
|
if (feeds.Any())
|
||||||
{
|
{
|
||||||
FeedGroups.Add(
|
this.FeedGroups.Add(
|
||||||
new FeedGroupVM
|
new FeedGroupVM
|
||||||
{
|
{
|
||||||
Feeds = feeds,
|
Feeds = feeds,
|
||||||
@ -151,8 +181,6 @@ else
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
RBLNews.Shared/Models/FilterFeedEventArg.cs
Normal file
13
RBLNews.Shared/Models/FilterFeedEventArg.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using RBLFeederCommon.Enums;
|
||||||
|
|
||||||
|
namespace RBLNews.Shared.Models;
|
||||||
|
|
||||||
|
public class FilterFeedEventArg
|
||||||
|
{
|
||||||
|
public RssFeedSources Source { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Value of the switch control
|
||||||
|
/// </summary>
|
||||||
|
public bool Value { get; set; }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user