0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-17 03:42:43 +00:00

Merge branch 'master' into pr/1592

This commit is contained in:
Trevor Buckner
2021-10-01 14:51:49 -04:00
49 changed files with 2195 additions and 1337 deletions

View File

@@ -31,8 +31,9 @@ const UserPage = createClass({
},
getInitialState : function() {
return {
sortType : 'alpha',
sortDir : 'asc'
sortType : 'alpha',
sortDir : 'asc',
filterString : ''
};
},
getUsernameWithS : function() {
@@ -52,7 +53,7 @@ const UserPage = createClass({
},
sortBrewOrder : function(brew){
if(!brew.title){brew.title = 'No Title';};
if(!brew.title){brew.title = 'No Title';}
const mapping = {
'alpha' : _.deburr(brew.title.toLowerCase()),
'created' : moment(brew.createdAt).format(),
@@ -91,6 +92,26 @@ const UserPage = createClass({
</td>;
},
handleFilterTextChange : function(e){
this.setState({
filterString : e.target.value
});
return;
},
renderFilterOption : function(){
return <td>
<label>
<i className='fas fa-search'></i>
<input
type='search'
placeholder='search title/description'
onChange={this.handleFilterTextChange}
/>
</label>
</td>;
},
renderSortOptions : function(){
return <div className='sort-container'>
<table>
@@ -115,6 +136,7 @@ const UserPage = createClass({
{`${(this.state.sortDir == 'asc' ? '\u25B2 ASC' : '\u25BC DESC')}`}
</button>
</td>
{this.renderFilterOption()}
</tr>
</tbody>
</table>
@@ -122,7 +144,12 @@ const UserPage = createClass({
},
getSortedBrews : function(){
return _.groupBy(this.props.brews, (brew)=>{
const testString = _.deburr(this.state.filterString).toLowerCase();
const brewCollection = this.state.filterString ? _.filter(this.props.brews, (brew)=>{
return (_.deburr(brew.title).toLowerCase().includes(testString)) ||
(_.deburr(brew.description).toLowerCase().includes(testString));
}) : this.props.brews;
return _.groupBy(brewCollection, (brew)=>{
return (brew.published ? 'published' : 'private');
});
},