mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-11 11:12:44 +00:00
Merge pull request #2316 from G-Ambatte/addSortTypeAndDirToURL-#2315
[UserPage] Add sort type and dir to URL
This commit is contained in:
@@ -30,10 +30,10 @@ const ListPage = createClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sortType : 'alpha',
|
filterString : this.props.query?.filter || '',
|
||||||
sortDir : 'asc',
|
sortType : this.props.query?.sort || 'alpha',
|
||||||
filterString : this.props.query?.filter || '',
|
sortDir : this.props.query?.dir || 'asc',
|
||||||
query : this.props.query,
|
query : this.props.query,
|
||||||
brewCollection : brewCollection
|
brewCollection : brewCollection
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -85,14 +85,18 @@ const ListPage = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleSortOptionChange : function(event){
|
handleSortOptionChange : function(event){
|
||||||
|
this.updateUrl(this.state.filterString, event.target.value, this.state.sortDir);
|
||||||
this.setState({
|
this.setState({
|
||||||
sortType : event.target.value
|
sortType : event.target.value
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSortDirChange : function(event){
|
handleSortDirChange : function(event){
|
||||||
|
const newDir = this.state.sortDir == 'asc' ? 'desc' : 'asc';
|
||||||
|
|
||||||
|
this.updateUrl(this.state.filterString, this.state.sortType, newDir);
|
||||||
this.setState({
|
this.setState({
|
||||||
sortDir : `${(this.state.sortDir == 'asc' ? 'desc' : 'asc')}`
|
sortDir : newDir
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -112,19 +116,22 @@ const ListPage = createClass({
|
|||||||
this.setState({
|
this.setState({
|
||||||
filterString : e.target.value,
|
filterString : e.target.value,
|
||||||
});
|
});
|
||||||
this.updateUrl(e.target.value);
|
this.updateUrl(e.target.value, this.state.sortType, this.state.sortDir);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUrl : function(filterTerm){
|
updateUrl : function(filterTerm, sortType, sortDir){
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const urlParams = new URLSearchParams(url.search);
|
const urlParams = new URLSearchParams(url.search);
|
||||||
if(urlParams.get('filter') == filterTerm)
|
|
||||||
return;
|
urlParams.set('sort', sortType);
|
||||||
|
urlParams.set('dir', sortDir);
|
||||||
|
|
||||||
if(!filterTerm)
|
if(!filterTerm)
|
||||||
urlParams.delete('filter');
|
urlParams.delete('filter');
|
||||||
else
|
else
|
||||||
urlParams.set('filter', filterTerm);
|
urlParams.set('filter', filterTerm);
|
||||||
|
|
||||||
url.search = urlParams;
|
url.search = urlParams;
|
||||||
window.history.replaceState(null, null, url);
|
window.history.replaceState(null, null, url);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user