diff --git a/client/homebrew/pages/userPage/userPage.jsx b/client/homebrew/pages/userPage/userPage.jsx
index 6527c3993..837da4359 100644
--- a/client/homebrew/pages/userPage/userPage.jsx
+++ b/client/homebrew/pages/userPage/userPage.jsx
@@ -24,7 +24,13 @@ const UserPage = createClass({
getDefaultProps : function() {
return {
username : '',
- brews : []
+ brews : [],
+ };
+ },
+ getInitialState : function() {
+ return {
+ sortType : 'alpha',
+ sortDir : 'asc'
};
},
getUsernameWithS : function() {
@@ -36,13 +42,82 @@ const UserPage = createClass({
renderBrews : function(brews){
if(!brews || !brews.length) return
No Brews.
;
- const sortedBrews = _.sortBy(brews, (brew)=>{ return brew.title; });
+ const sortedBrews = this.sortBrews(brews, this.state.sortType);
return _.map(sortedBrews, (brew, idx)=>{
return ;
});
},
+ sortBrewOrder : function(brew){
+ const mapping = {
+ 'alpha' : _.deburr(brew.title.toLowerCase()),
+ 'created' : brew.createdAt,
+ 'updated' : brew.updatedAt,
+ 'views' : brew.views,
+ 'latest' : brew.lastViewed
+ };
+ return mapping[this.state.sortType];
+ },
+
+ sortBrews : function(brews){
+ return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
+ },
+
+ handleSortOptionChange : function(event){
+ this.setState({
+ sortType : event.target.value
+ });
+ },
+
+ handleSortDirChange : function(event){
+ this.setState({
+ sortDir : `${(this.state.sortDir == 'asc' ? 'desc' : 'asc')}`
+ });
+ },
+
+ renderSortOption : function(sortTitle, sortValue){
+ return
+
+ | ;
+ },
+
+ renderSortOptions : function(){
+ return
+
+
+
+
+ Sort by :
+ |
+ {this.renderSortOption('Title', 'alpha')}
+ {this.renderSortOption('Created Date', 'created')}
+ {this.renderSortOption('Updated Date', 'updated')}
+ {this.renderSortOption('Views', 'views')}
+ {/* {this.renderSortOption('Latest', 'latest')} */}
+
+ Direction :
+ |
+
+
+ |
+
+
+
+
;
+ },
+
getSortedBrews : function(){
return _.groupBy(this.props.brews, (brew)=>{
return (brew.published ? 'published' : 'private');
@@ -64,6 +139,7 @@ const UserPage = createClass({
+ {this.renderSortOptions()}
{this.getUsernameWithS()} brews
{this.renderBrews(brews.published)}
diff --git a/client/homebrew/pages/userPage/userPage.less b/client/homebrew/pages/userPage/userPage.less
index d002966de..c7e8621e3 100644
--- a/client/homebrew/pages/userPage/userPage.less
+++ b/client/homebrew/pages/userPage/userPage.less
@@ -30,4 +30,44 @@
}
}
+ .sort-container{
+ font-family : 'Open Sans', sans-serif;
+ position : fixed;
+ top : 35px;
+ border : 2px solid #58180D;
+ width : 675px;
+ background-color : #EEE5CE;
+ padding : 2px;
+ text-align : center;
+ z-index : 15;
+ h6{
+ text-transform : uppercase;
+ font-family : 'Open Sans', sans-serif;
+ font-size : 11px;
+ font-weight : bold;
+ color : #58180D;
+ }
+ table{
+ margin : 0px;
+ vertical-align : middle;
+ tbody tr{
+ background-color: transparent !important;
+ button{
+ background-color : transparent;
+ color : #58180D;
+ font-family : 'Open Sans', sans-serif;
+ font-size : 11px;
+ text-transform : uppercase;
+ font-weight : normal;
+ &.active{
+ font-weight : bold;
+ border : 2px solid #58180D;
+ }
+ &.sortDir{
+ width : 75px;
+ }
+ }
+ }
+ }
+ }
}