Skip to content

Commit

Permalink
Merge branch 'master' into experimentalBrewLocking-naturalcrit#3326
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Ambatte authored Feb 28, 2024
2 parents 802da29 + 3778b4c commit df3db14
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 28 deletions.
12 changes: 10 additions & 2 deletions client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const BrewItem = createClass({
authors : [],
stubbed : true
},
reportError : ()=>{}
updateListFilter : ()=>{},
reportError : ()=>{}
};
},

Expand All @@ -44,6 +45,10 @@ const BrewItem = createClass({
});
},

updateFilter : function(type, term){
this.props.updateListFilter(type, term);
},

renderDeleteBrewLink : function(){
if(!this.props.brew.editId) return;

Expand Down Expand Up @@ -109,6 +114,9 @@ const BrewItem = createClass({
const brew = this.props.brew;
if(Array.isArray(brew.tags)) { // temporary fix until dud tags are cleaned
brew.tags = brew.tags?.filter((tag)=>tag); //remove tags that are empty strings
brew.tags.sort((a, b)=>{
return a.indexOf(':') - b.indexOf(':') != 0 ? a.indexOf(':') - b.indexOf(':') : a.toLowerCase().localeCompare(b.toLowerCase());
});
}
const dateFormatString = 'YYYY-MM-DD HH:mm:ss';

Expand All @@ -129,7 +137,7 @@ const BrewItem = createClass({
<i className='fas fa-tags'/>
{brew.tags.map((tag, idx)=>{
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
return <span key={idx} className={matches[1]}>{matches[2]}</span>;
return <span key={idx} className={matches[1]} onClick={()=>{this.updateFilter(tag);}}>{matches[2]}</span>;
})}
</div>
</> : <></>
Expand Down
35 changes: 35 additions & 0 deletions client/homebrew/pages/basePages/listPage/brewItem/brewItem.less
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,41 @@
white-space: nowrap;
display: inline-block;
font-weight: bold;
border-color: currentColor;
cursor : pointer;
&:before {
font-family: 'Font Awesome 5 Free';
font-size: 12px;
margin-right: 3px;
}
&.type {
background-color: #0080003b;
color: #008000;
&:before{
content: '\f0ad';
}
}
&.group {
background-color: #5050503b;
color: #000000;
&:before{
content: '\f500';
}
}
&.meta {
background-color: #0000803b;
color: #000080;
&:before{
content: '\f05a';
}
}
&.system {
background-color: #8000003b;
color: #800000;
&:before{
content: '\f518';
}
}
}
&:hover{
.links{
Expand Down
55 changes: 49 additions & 6 deletions client/homebrew/pages/basePages/listPage/listPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ListPage = createClass({

return {
filterString : this.props.query?.filter || '',
filterTags : [],
sortType : this.props.query?.sort || null,
sortDir : this.props.query?.dir || null,
query : this.props.query,
Expand Down Expand Up @@ -82,7 +83,7 @@ const ListPage = createClass({
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;

return _.map(brews, (brew, idx)=>{
return <BrewItem brew={brew} key={idx} reportError={this.props.reportError}/>;
return <BrewItem brew={brew} key={idx} reportError={this.props.reportError} updateListFilter={ (tag)=>{ this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, tag); }}/>;
});
},

Expand Down Expand Up @@ -136,13 +137,33 @@ const ListPage = createClass({
return;
},

updateUrl : function(filterTerm, sortType, sortDir){
updateUrl : function(filterTerm, sortType, sortDir, filterTag=''){
const url = new URL(window.location.href);
const urlParams = new URLSearchParams(url.search);

urlParams.set('sort', sortType);
urlParams.set('dir', sortDir);

let filterTags = urlParams.getAll('tag');
if(filterTag != '') {
if(filterTags.findIndex((tag)=>{return tag.toLowerCase()==filterTag.toLowerCase();}) == -1){
filterTags.push(filterTag);
} else {
filterTags = filterTags.filter((tag)=>{ return tag.toLowerCase() != filterTag.toLowerCase(); });
}
}
urlParams.delete('tag');
// Add tags to URL in the order they were clicked
filterTags.forEach((tag)=>{ urlParams.append('tag', tag); });
// Sort tags before updating state
filterTags.sort((a, b)=>{
return a.indexOf(':') - b.indexOf(':') != 0 ? a.indexOf(':') - b.indexOf(':') : a.toLowerCase().localeCompare(b.toLowerCase());
});

this.setState({
filterTags
});

if(!filterTerm)
urlParams.delete('filter');
else
Expand All @@ -166,6 +187,16 @@ const ListPage = createClass({
</div>;
},

renderTagsOptions : function(){
if(this.state.filterTags?.length == 0) return;
return <div className='tags-container'>
{_.map(this.state.filterTags, (tag, idx)=>{
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
return <span key={idx} className={matches[1]} onClick={()=>{ this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, tag); }}>{matches[2]}</span>;
})}
</div>;
},

renderSortOptions : function(){
return <div className='sort-container'>
<h6>Sort by :</h6>
Expand All @@ -176,24 +207,35 @@ const ListPage = createClass({
{/* {this.renderSortOption('Latest', 'latest')} */}

{this.renderFilterOption()}



</div>;
},

getSortedBrews : function(brews){
const testString = _.deburr(this.state.filterString).toLowerCase();

brews = _.filter(brews, (brew)=>{
// Filter by user entered text
const brewStrings = _.deburr([
brew.title,
brew.description,
brew.tags].join('\n')
.toLowerCase());

return brewStrings.includes(testString);
const filterTextTest = brewStrings.includes(testString);

// Filter by user selected tags
let filterTagTest = true;
if(this.state.filterTags.length > 0){
filterTagTest = Array.isArray(brew.tags) && this.state.filterTags?.every((tag)=>{
return brew.tags.findIndex((brewTag)=>{
return brewTag.toLowerCase() == tag.toLowerCase();
}) >= 0;
});
}

return filterTextTest && filterTagTest;
});

return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
},

Expand Down Expand Up @@ -224,6 +266,7 @@ const ListPage = createClass({
<link href='/themes/V3/5ePHB/style.css' rel='stylesheet'/>
{this.props.navItems}
{this.renderSortOptions()}
{this.renderTagsOptions()}

<div className='content V3'>
<div className='page'>
Expand Down
64 changes: 63 additions & 1 deletion client/homebrew/pages/basePages/listPage/listPage.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
}
}
.sort-container{
.sort-container {
font-family : 'Open Sans', sans-serif;
position : sticky;
top : 0;
Expand Down Expand Up @@ -125,4 +125,66 @@


}
.tags-container {
height : 30px;
background-color : #555;
border-top : 1px solid #666;
border-bottom : 1px solid #666;
color : white;
display : flex;
justify-content : center;
align-items : center;
column-gap : 15px;
row-gap : 5px;
flex-wrap : wrap;
span {
font-family : 'Open Sans', sans-serif;
font-size : 11px;
font-weight : bold;
border : 1px solid;
border-radius : 3px;
padding : 3px;
cursor : pointer;
color: #dfdfdf;
&:before {
font-family: 'Font Awesome 5 Free';
font-size: 12px;
margin-right: 3px;
}
&:after {
content: '\f00d';
font-family: 'Font Awesome 5 Free';
font-size: 12px;
margin-left: 3px;
}
&.type {
background-color: #008000;
border-color: #00a000;
&:before{
content: '\f0ad';
}
}
&.group {
background-color: #505050;
border-color: #000000;
&:before{
content: '\f500';
}
}
&.meta {
background-color: #000080;
border-color: #0000a0;
&:before{
content: '\f05a';
}
}
&.system {
background-color: #800000;
border-color: #a00000;
&:before{
content: '\f518';
}
}
}
}
}
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"vitreum": "git+https://[email protected]/calculuschild/vitreum.git"
},
"devDependencies": {
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-react": "^7.33.2",
"jest": "^29.7.0",
Expand Down
1 change: 0 additions & 1 deletion themes/V3/5ePHB/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@
margin-left : -0.16cm;
background-color : var(--HB_Color_MonsterStatBackground);
background-image : @monsterBlockBackground;
background-attachment : unset;
background-blend-mode : overlay;
border-style : solid;
border-width : 7px 6px;
Expand Down

0 comments on commit df3db14

Please sign in to comment.