From 2fcccfb48f30a44eadebe9e40afe805dbe310089 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 1 Sep 2022 23:55:14 +1200 Subject: [PATCH 1/2] Expand filtering functionality --- .../homebrew/pages/basePages/listPage/listPage.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/listPage.jsx b/client/homebrew/pages/basePages/listPage/listPage.jsx index e546e2c7f..40534b3f9 100644 --- a/client/homebrew/pages/basePages/listPage/listPage.jsx +++ b/client/homebrew/pages/basePages/listPage/listPage.jsx @@ -141,9 +141,18 @@ const ListPage = createClass({ getSortedBrews : function(brews){ const testString = _.deburr(this.state.filterString).toLowerCase(); + + const checkString = (stringToTest)=>{ + return (_.deburr(stringToTest).toLowerCase().includes(testString)); + }; + brews = _.filter(brews, (brew)=>{ - return (_.deburr(brew.title).toLowerCase().includes(testString)) || - (_.deburr(brew.description).toLowerCase().includes(testString)); + const brewStrings = [] + .concat(brew.title) + .concat(brew.description) + .concat(brew.tags); + + return _.filter(brewStrings, (brewString)=>{return checkString(brewString);}).length > 0; }); return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir); From 85cad49b03f525801d7b1190819499b35c33b677 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 3 Sep 2022 22:28:03 +1200 Subject: [PATCH 2/2] Simplify getSortedBrews logic --- .../pages/basePages/listPage/listPage.jsx | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/listPage.jsx b/client/homebrew/pages/basePages/listPage/listPage.jsx index fef13140d..eb96c43da 100644 --- a/client/homebrew/pages/basePages/listPage/listPage.jsx +++ b/client/homebrew/pages/basePages/listPage/listPage.jsx @@ -1,3 +1,4 @@ +/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/ require('./listPage.less'); const React = require('react'); const createClass = require('create-react-class'); @@ -30,10 +31,10 @@ const ListPage = createClass({ }); return { - filterString : this.props.query?.filter || '', - sortType : this.props.query?.sort || 'alpha', - sortDir : this.props.query?.dir || 'asc', - query : this.props.query, + filterString : this.props.query?.filter || '', + sortType : this.props.query?.sort || 'alpha', + sortDir : this.props.query?.dir || 'asc', + query : this.props.query, brewCollection : brewCollection }; }, @@ -184,19 +185,15 @@ const ListPage = createClass({ getSortedBrews : function(brews){ const testString = _.deburr(this.state.filterString).toLowerCase(); - const checkString = (stringToTest)=>{ - return (_.deburr(stringToTest).toLowerCase().includes(testString)); - }; - brews = _.filter(brews, (brew)=>{ - const brewStrings = [] - .concat(brew.title) - .concat(brew.description) - .concat(brew.tags); + const brewStrings = _.deburr([ + brew.title, + brew.description, + brew.tags].join('\n') + .toLowerCase()); - return _.filter(brewStrings, (brewString)=>{return checkString(brewString);}).length > 0; + return brewStrings.includes(testString); }); - return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir); },