mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 18:52:38 +00:00
Add separate tag filter
This commit is contained in:
@@ -36,6 +36,7 @@ const ListPage = createClass({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
filterString : this.props.query?.filter || '',
|
filterString : this.props.query?.filter || '',
|
||||||
|
filterTags : [],
|
||||||
sortType : this.props.query?.sort || null,
|
sortType : this.props.query?.sort || null,
|
||||||
sortDir : this.props.query?.dir || null,
|
sortDir : this.props.query?.dir || null,
|
||||||
query : this.props.query,
|
query : this.props.query,
|
||||||
@@ -138,18 +139,31 @@ const ListPage = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateListFilter : function(type, term){
|
updateListFilter : function(type, term){
|
||||||
// console.log(`ListPage: TYPE: ${type}; TERM: ${term}`);
|
this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, term);
|
||||||
const e = { target: { value: term } };
|
|
||||||
this.handleFilterTextChange(e);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUrl : function(filterTerm, sortType, sortDir){
|
updateUrl : function(filterTerm, sortType, sortDir, filterTag=''){
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const urlParams = new URLSearchParams(url.search);
|
const urlParams = new URLSearchParams(url.search);
|
||||||
|
|
||||||
urlParams.set('sort', sortType);
|
urlParams.set('sort', sortType);
|
||||||
urlParams.set('dir', sortDir);
|
urlParams.set('dir', sortDir);
|
||||||
|
|
||||||
|
let filterTags = urlParams.getAll('tag');
|
||||||
|
if(filterTag != '') {
|
||||||
|
if(!filterTags.includes(filterTag)){
|
||||||
|
filterTags.push(filterTag);
|
||||||
|
} else {
|
||||||
|
filterTags = filterTags.filter((tag)=>{ return tag != filterTag; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
urlParams.delete('tag');
|
||||||
|
filterTags.forEach((tag)=>{ urlParams.append('tag', tag); });
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
filterTags
|
||||||
|
});
|
||||||
|
|
||||||
if(!filterTerm)
|
if(!filterTerm)
|
||||||
urlParams.delete('filter');
|
urlParams.delete('filter');
|
||||||
else
|
else
|
||||||
@@ -201,6 +215,15 @@ const ListPage = createClass({
|
|||||||
|
|
||||||
return brewStrings.includes(testString);
|
return brewStrings.includes(testString);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(this.state.filterTags.length > 0) {
|
||||||
|
brews = _.filter(brews, (brew)=>{
|
||||||
|
return this.state.filterTags.some((tag)=>{
|
||||||
|
return brew.tags?.includes(tag);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
|
return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user