0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +00:00

Initial pass at UserPage filtering to/from URL

This commit is contained in:
G.Ambatte
2022-03-25 11:20:16 +13:00
parent 323ccf3b25
commit 1c641e3aff
3 changed files with 26 additions and 4 deletions

View File

@@ -46,7 +46,7 @@ const Homebrew = createClass({
<Route path='/share/:id' component={(routeProps)=><SharePage id={routeProps.match.params.id} brew={this.props.brew} />}/>
<Route path='/new/:id' component={(routeProps)=><NewPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
<Route path='/new' exact component={(routeProps)=><NewPage />}/>
<Route path='/user/:username' component={(routeProps)=><UserPage username={routeProps.match.params.username} brews={this.props.brews} />}/>
<Route path='/user/:username' component={(routeProps)=><UserPage username={routeProps.match.params.username} brews={this.props.brews} query={queryString.parse(routeProps.location.search)}/>}/>
<Route path='/print/:id' component={(routeProps)=><PrintPage brew={this.props.brew} query={queryString.parse(routeProps.location.search)} />}/>
<Route path='/print' exact component={(routeProps)=><PrintPage query={queryString.parse(routeProps.location.search)} />}/>
<Route path='/changelog' exact component={()=><SharePage brew={this.props.brew} />}/>

View File

@@ -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,39 @@ const ListPage = createClass({
handleFilterTextChange : function(e){
this.setState({
filterString : e.target.value
filterString : e.target.value,
});
return;
},
handleKeys : function(e){
if(e.key === 'Enter') {
this.updateUrl(e.target.value);
}
},
updateUrl : function(filterTerm){
const url = new URL(window.location.href);
const urlParams = new URLSearchParams(url.search);
if(urlParams.get('filter') == filterTerm) return;
urlParams.set('filter', filterTerm);
if(!filterTerm) urlParams.delete('filter');
url.search = urlParams;
window.location.replace(url.href);
},
renderFilterOption : function(){
return <td>
<label>
<i className='fas fa-search'></i>
<input
type='search'
autoFocus={true}
placeholder='search title/description'
onChange={this.handleFilterTextChange}
onFocus={(e)=>{e.target.select();}}
onKeyDown={(e)=>{this.handleKeys(e);}}
value={this.state.filterString}
/>
</label>
</td>;

View File

@@ -19,6 +19,7 @@ const UserPage = createClass({
return {
username : '',
brews : [],
query : ''
};
},
getInitialState : function() {
@@ -62,7 +63,7 @@ const UserPage = createClass({
},
render : function(){
return <ListPage brewCollection={this.state.brewCollection} navItems={this.navItems()}></ListPage>;
return <ListPage brewCollection={this.state.brewCollection} navItems={this.navItems()} query={this.props.query}></ListPage>;
}
});