mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 07:42:39 +00:00
Merge pull request #2090 from G-Ambatte/addQueryToUserPageUrl
Add UserPage filtering to/from URL
This commit is contained in:
@@ -24,7 +24,8 @@ const ListPage = createClass({
|
||||
return {
|
||||
sortType : 'alpha',
|
||||
sortDir : 'asc',
|
||||
filterString : ''
|
||||
filterString : this.props.query?.filter || '',
|
||||
query : this.props.query
|
||||
};
|
||||
},
|
||||
|
||||
@@ -74,19 +75,35 @@ const ListPage = createClass({
|
||||
|
||||
handleFilterTextChange : function(e){
|
||||
this.setState({
|
||||
filterString : e.target.value
|
||||
filterString : e.target.value,
|
||||
});
|
||||
this.updateUrl(e.target.value);
|
||||
return;
|
||||
},
|
||||
|
||||
updateUrl : function(filterTerm){
|
||||
const url = new URL(window.location.href);
|
||||
const urlParams = new URLSearchParams(url.search);
|
||||
if(urlParams.get('filter') == filterTerm)
|
||||
return;
|
||||
if(!filterTerm)
|
||||
urlParams.delete('filter');
|
||||
else
|
||||
urlParams.set('filter', filterTerm);
|
||||
url.search = urlParams;
|
||||
window.history.replaceState(null, null, url);
|
||||
},
|
||||
|
||||
renderFilterOption : function(){
|
||||
return <td>
|
||||
<label>
|
||||
<i className='fas fa-search'></i>
|
||||
<input
|
||||
type='search'
|
||||
placeholder='search title/description'
|
||||
autoFocus={true}
|
||||
placeholder='filter title/description'
|
||||
onChange={this.handleFilterTextChange}
|
||||
value={this.state.filterString}
|
||||
/>
|
||||
</label>
|
||||
</td>;
|
||||
|
||||
Reference in New Issue
Block a user