@@ -395,6 +395,7 @@ UserPageVw = pageVw.extend({
395395 self . setCustomStyles ( ) ;
396396 self . setState ( self . state , self . currentItemHash , { replaceHistory : true } ) ;
397397 self . $backToTop = self . $ ( '.backToTop' ) ;
398+ self . $categorySelect = self . $ ( '.js-categories' ) ;
398399
399400 //check if user is blocked
400401 if ( ! self . options . ownPage && isBlocked ) {
@@ -598,16 +599,24 @@ UserPageVw = pageVw.extend({
598599 }
599600 } ,
600601
601- setCategory : function ( category ) {
602- var $select ;
602+ setCategorySelect : function ( category ) {
603+ if ( category && this . $categorySelect . val ( ) !== category &&
604+ this . $categorySelect . find ( 'option[value="' + category + '"]' ) . length ) {
605+ this . $categorySelect . val ( category ) ;
606+ }
607+ this . showCategory ( category ) ;
608+ } ,
603609
604- if ( category ) {
605- $select = this . $el . find ( '.js-categories' ) ;
610+ categoryChanged : function ( ) {
611+ this . showCategory ( this . $categorySelect . val ( ) ) ;
612+ } ,
606613
607- if ( $select . val ( ) !== category && $select . find ( 'option[value="' + category + '"]' ) . length ) {
608- $select . val ( category ) ;
609- this . categoryChanged ( ) ;
610- }
614+ showCategory : function ( category ) {
615+ if ( this . itemList ) {
616+ this . itemList . category = category ;
617+ this . itemList . render ( ) ;
618+ } else {
619+ this . renderItems ( this . cachedListings ) ;
611620 }
612621 } ,
613622
@@ -627,10 +636,6 @@ UserPageVw = pageVw.extend({
627636 }
628637 } ,
629638
630- categoryChanged : function ( ) {
631- this . renderItems ( this . listings . get ( 'listings' ) ) ;
632- } ,
633-
634639 toggleFollowButtons : function ( followed ) {
635640 var followBtn = this . $ ( '.js-follow' ) ,
636641 unfollowBtn = this . $ ( '.js-unfollow' ) ;
@@ -847,7 +852,6 @@ UserPageVw = pageVw.extend({
847852
848853 renderItems : function ( model , skipNSFWmodal ) {
849854 var self = this ,
850- select = this . $el . find ( '.js-categories' ) ,
851855 selectOptions = [ ] ,
852856 addressCountries = self . options . userModel . get ( 'shipping_addresses' ) . map ( function ( address ) {
853857 return address . country ;
@@ -857,38 +861,38 @@ UserPageVw = pageVw.extend({
857861 addressCountries . push ( userCountry ) ;
858862 skipNSFWmodal = skipNSFWmodal || this . skipNSFWmodal ;
859863 model = model || [ ] ;
860- __ . each ( model , function ( arrayItem ) {
864+ __ . each ( model , ( arrayItem ) => {
861865
862- if ( ! self . showNSFWContent && ! self . showNSFW && ! skipNSFWmodal && arrayItem . nsfw ) {
866+ if ( ! this . showNSFWContent && ! this . showNSFW && ! skipNSFWmodal && arrayItem . nsfw ) {
863867 arrayItem . cloak = true ;
864868 } else {
865869 arrayItem . cloak = false ;
866870 }
867- arrayItem . userCurrencyCode = self . options . userModel . get ( 'currency_code' ) ;
868- arrayItem . serverUrl = self . options . userModel . get ( 'serverUrl' ) ;
871+ arrayItem . userCurrencyCode = this . options . userModel . get ( 'currency_code' ) ;
872+ arrayItem . serverUrl = this . options . userModel . get ( 'serverUrl' ) ;
869873 arrayItem . showAvatar = false ;
870- arrayItem . avatar_hash = self . model . get ( 'page' ) . profile . avatar_hash ;
871- arrayItem . handle = self . model . get ( 'page' ) . profile . handle ;
872- arrayItem . userID = self . pageID ;
873- arrayItem . ownPage = self . options . ownPage ;
874+ arrayItem . avatar_hash = this . model . get ( 'page' ) . profile . avatar_hash ;
875+ arrayItem . handle = this . model . get ( 'page' ) . profile . handle ;
876+ arrayItem . userID = this . pageID ;
877+ arrayItem . ownPage = this . options . ownPage ;
874878 arrayItem . onUserPage = true ;
875879 arrayItem . userCountries = addressCountries ;
876880 arrayItem . skipNSFWmodal = skipNSFWmodal ;
877- if ( arrayItem . category != "" && self . $el . find ( '.js-categories option[value="' + arrayItem . category + '"]' ) . length == 0 ) {
881+ if ( arrayItem . category != "" && this . $el . find ( '.js-categories option[value="' + arrayItem . category + '"]' ) . length == 0 ) {
878882 selectOptions [ arrayItem . category ] = true ;
879883 }
880- if ( self . options . ownPage === true ) {
881- arrayItem . imageURL = self . options . userModel . get ( 'serverUrl' ) + "get_image?hash=" + arrayItem . thumbnail_hash ;
884+ if ( this . options . ownPage === true ) {
885+ arrayItem . imageURL = this . options . userModel . get ( 'serverUrl' ) + "get_image?hash=" + arrayItem . thumbnail_hash ;
882886 } else {
883- arrayItem . imageURL = self . options . userModel . get ( 'serverUrl' ) + "get_image?hash=" + arrayItem . thumbnail_hash + "&guid=" + self . pageID ;
887+ arrayItem . imageURL = this . options . userModel . get ( 'serverUrl' ) + "get_image?hash=" + arrayItem . thumbnail_hash + "&guid=" + this . pageID ;
884888 }
885889 } ) ;
886890
887- Object . keys ( selectOptions ) . sort ( ) . forEach ( function ( selectOption ) {
891+ Object . keys ( selectOptions ) . sort ( ) . forEach ( ( selectOption ) => {
888892 var opt = document . createElement ( 'option' ) ;
889893 opt . value = selectOption ;
890894 opt . innerHTML = selectOption ;
891- select . append ( opt ) ;
895+ this . $categorySelect . append ( opt ) ;
892896 } ) ;
893897
894898 this . itemList = new itemListView ( {
@@ -897,7 +901,7 @@ UserPageVw = pageVw.extend({
897901 title : window . polyglot . t ( 'NoListings' ) ,
898902 message : "" ,
899903 userModel : this . options . userModel ,
900- category : this . $el . find ( '.js-categories' ) . val ( )
904+ category : this . $categorySelect . val ( ) ,
901905 } ) ;
902906
903907 this . registerChild ( this . itemList ) ;
@@ -1148,16 +1152,11 @@ UserPageVw = pageVw.extend({
11481152 } ,
11491153
11501154 storeTabClick : function ( e ) {
1151- if ( this . $el . find ( '.js-categories' ) . val ( ) != "all" ) {
1152- $ ( ".js-categories option[value='all']" ) . attr ( "selected" , "selected" ) ;
1153- this . categoryChanged ( ) ;
1154- }
1155-
11561155 this . storeClick ( e ) ;
11571156 } ,
11581157
11591158 storeCatClick : function ( e ) {
1160- this . setCategory ( $ ( e . target ) . text ( ) ) ;
1159+ this . setCategorySelect ( $ ( e . target ) . text ( ) ) ;
11611160 this . storeClick ( e ) ;
11621161 } ,
11631162
0 commit comments