From 00d0d1526447b33058a90c624da093e4bc32ff13 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Thu, 7 Jun 2018 12:52:52 -0500 Subject: [PATCH] try adding rule count to tagline ref #272 --- .../V1/Controllers/RulesController.cs | 2 +- .../ClientApp/components/Home.tsx | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/FilterLists.Api/V1/Controllers/RulesController.cs b/src/FilterLists.Api/V1/Controllers/RulesController.cs index 2b2f0518e..2a1f9f8cc 100644 --- a/src/FilterLists.Api/V1/Controllers/RulesController.cs +++ b/src/FilterLists.Api/V1/Controllers/RulesController.cs @@ -14,6 +14,6 @@ public RulesController(RuleService ruleService) } [HttpGet] - public async Task Index() => Json(new {Count = await _ruleService.GetCountAllActiveRules()}); + public async Task Index() => Json(await _ruleService.GetCountAllActiveRules()); } } \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/Home.tsx b/src/FilterLists.Web/ClientApp/components/Home.tsx index d143eb65d..6b2d4e037 100644 --- a/src/FilterLists.Web/ClientApp/components/Home.tsx +++ b/src/FilterLists.Web/ClientApp/components/Home.tsx @@ -7,7 +7,9 @@ import ListDetails from "./ListDetails"; interface IFilterListsState { filterLists: IFilterListSummaryDto[]; - loading: boolean; + loadingLists: boolean; + ruleCount: number; + loadingRuleCount: boolean; } export class Home extends React.Component, IFilterListsState> { @@ -15,17 +17,19 @@ export class Home extends React.Component, IFilterListsS super(props); this.state = { filterLists: [], - loading: true + loadingLists: true, + ruleCount: 0, + loadingRuleCount: true }; } render() { - const contents = this.state.loading + const contents = this.state.loadingLists || this.state.loadingRuleCount ?

Loading...

:
- {Home.renderTagline(this.state.filterLists)} + {Home.renderTagline(this.state.filterLists, this.state.ruleCount)} {Home.renderFilterListsTable(this.state.filterLists)}
; return
@@ -39,14 +43,24 @@ export class Home extends React.Component, IFilterListsS .then(data => { this.setState({ filterLists: data, - loading: false + loadingLists: false + }); + }); + fetch("https://filterlists.com/api/v1/rules") + .then(response => response.json() as Promise) + .then(data => { + this.setState({ + ruleCount: data, + loadingRuleCount: false }); }); } - private static renderTagline(filterLists: IFilterListSummaryDto[]) { + private static renderTagline(filterLists: IFilterListSummaryDto[], ruleCount: number) { return

- The independent, comprehensive directory of {filterLists.length} filter and host lists for advertisements, trackers, malware, and annoyances. + The independent, comprehensive directory of {filterLists.length + } filter and host lists containing {ruleCount + } unique rules for advertisements, trackers, malware, and annoyances.

; }