+
@feed.Title
@@ -78,7 +83,7 @@ else
private IEnumerable> SourceGroupings { get; set; } = new List>();
- private List activeFilters = new List();
+ private List activeFeedSources = new List();
protected override void OnInitialized()
@@ -89,6 +94,19 @@ else
}
+ private void SetFilter()
+ {
+ this.activeFeedSources.Clear();
+
+ IEnumerable enumerable = this.SourceGroupings.Select(grp => grp.Key).Distinct();
+
+ foreach (int i in enumerable)
+ {
+ this.activeFeedSources.Add((RssFeedSources)i);
+ }
+ }
+
+
private async void LoadFeeds()
{
// 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);
+ SetFilter();
+
+ this.FilterFeeds();
+
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();
- foreach (FeedGroupVM fg in FeedDataService.Feeds.FeedGroups)
+ this.FilterFeeds();
+
+ StateHasChanged();
+ }
+
+
+ private void FilterFeeds()
+ {
+ this.FeedGroups = new List();
+ foreach (FeedGroupVM fg in this.FeedDataService.Feeds.FeedGroups)
{
- List feeds = fg.Feeds.Where(f => activeFilters.Contains((RssFeedSources)f.Source)).ToList();
+ List feeds = fg.Feeds.Where(f => this.activeFeedSources.Contains((RssFeedSources)f.Source)).ToList();
if (feeds.Any())
{
- FeedGroups.Add(
+ this.FeedGroups.Add(
new FeedGroupVM
{
Feeds = feeds,
@@ -151,8 +181,6 @@ else
});
}
}
-
- StateHasChanged();
}
diff --git a/RBLNews.Shared/Models/FilterFeedEventArg.cs b/RBLNews.Shared/Models/FilterFeedEventArg.cs
new file mode 100644
index 0000000..cb61e7a
--- /dev/null
+++ b/RBLNews.Shared/Models/FilterFeedEventArg.cs
@@ -0,0 +1,13 @@
+using RBLFeederCommon.Enums;
+
+namespace RBLNews.Shared.Models;
+
+public class FilterFeedEventArg
+{
+ public RssFeedSources Source { get; set; }
+
+ ///
+ /// Value of the switch control
+ ///
+ public bool Value { get; set; }
+}
\ No newline at end of file