diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 7abed0dcb..2021ac2d3 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -3495,3 +3495,13 @@ class ApiController(RedditController, OAuth2ResourceController): giftmessage=None, comment=comment._fullname, )) + + @json_validate( + VUser(), + VModhash(), + collapsed=VBoolean('collapsed'), + ) + def POST_set_left_bar_collapsed(self, responder, collapsed): + c.user.pref_collapse_left_bar = collapsed + c.user._commit() + diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 703619ab2..cee50956b 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -616,6 +616,8 @@ class Reddit(Templated): if self.show_chooser: classes.add('with-listing-chooser') + if c.user.pref_collapse_left_bar: + classes.add('listing-chooser-collapsed') if self.extra_page_classes: classes.update(self.extra_page_classes) diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index a249fba3e..2104df780 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -91,6 +91,7 @@ class Account(Thing): pref_show_sponsorships = True, pref_highlight_new_comments = True, pref_monitor_mentions=True, + pref_collapse_left_bar=False, mobile_compress = False, mobile_thumbnail = True, trusted_sponsor = False, diff --git a/r2/r2/public/static/js/multi.js b/r2/r2/public/static/js/multi.js index d9e8b1fff..c9479ce16 100644 --- a/r2/r2/public/static/js/multi.js +++ b/r2/r2/public/static/js/multi.js @@ -609,6 +609,12 @@ r.multi.ListingChooser = Backbone.View.extend({ initialize: function() { this.$el.addClass('initialized') + // transition collapsed state to server pref + if (store.get('ui.collapse.listingchooser') == true) { + this.toggleCollapsed(true) + store.remove('ui.collapse.listingchooser') + } + // HACK: fudge page heights for long lists of multis / short pages var thisHeight = this.$('.contents').height(), bodyHeight = $('body').height() @@ -629,8 +635,14 @@ r.multi.ListingChooser = Backbone.View.extend({ } }, - toggleCollapsed: function() { - $('body').toggleClass('listing-chooser-collapsed') - store.set('ui.collapse.listingchooser', $('body').is('.listing-chooser-collapsed')) + toggleCollapsed: function(value) { + $('body').toggleClass('listing-chooser-collapsed', value) + Backbone.ajax({ + type: 'POST', + url: '/api/set_left_bar_collapsed.json', + data: { + 'collapsed': $('body').is('.listing-chooser-collapsed') + } + }) } }) diff --git a/r2/r2/public/static/js/uibase.js b/r2/r2/public/static/js/uibase.js index f9aa1eaba..ee21f5a7a 100644 --- a/r2/r2/public/static/js/uibase.js +++ b/r2/r2/public/static/js/uibase.js @@ -91,10 +91,3 @@ r.ui.Summarize.prototype = { e.preventDefault() } } - -r.ui.collapseListingChooser = function() { - if (store.get('ui.collapse.listingchooser') == true) { - $('body').addClass('listing-chooser-collapsed') - } -} - diff --git a/r2/r2/templates/listingchooser.html b/r2/r2/templates/listingchooser.html index ef4412d62..4152bb34e 100644 --- a/r2/r2/templates/listingchooser.html +++ b/r2/r2/templates/listingchooser.html @@ -37,7 +37,6 @@ %endfor %def> -