0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

Merge pull request #1573 from G-Ambatte/addFilteringToUserPage

User Page filtering
This commit is contained in:
Trevor Buckner
2021-08-27 23:03:10 -04:00
committed by GitHub
2 changed files with 36 additions and 5 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');
});
},

View File

@@ -34,8 +34,9 @@
font-family : 'Open Sans', sans-serif;
position : fixed;
top : 35px;
left : calc(50vw - 408px);
border : 2px solid #58180D;
width : 675px;
width : 800px;
background-color : #EEE5CE;
padding : 2px;
text-align : center;
@@ -52,6 +53,9 @@
vertical-align : middle;
tbody tr{
background-color: transparent !important;
i{
padding-right : 5px
}
button{
background-color : transparent;
color : #58180D;