From b11595de0630b3a5a8021165a6a1379e7b81f6d3 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 18 May 2015 15:07:04 +0930 Subject: [PATCH] Refresh discussion after logging in. Fixes #68 --- .../js/forum/src/components/discussion-list.js | 2 +- .../js/forum/src/components/discussion-page.js | 18 ++++++++++++++---- .../src/initializers/discussion-controls.js | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/framework/core/js/forum/src/components/discussion-list.js b/framework/core/js/forum/src/components/discussion-list.js index 84ff225e8..fba5b8619 100644 --- a/framework/core/js/forum/src/components/discussion-list.js +++ b/framework/core/js/forum/src/components/discussion-list.js @@ -21,7 +21,7 @@ export default class DiscussionList extends Component { this.refresh(); - app.session.on('loggedIn', this.loggedInHandler = this.refresh.bind(this)) + app.session.on('loggedIn', this.loggedInHandler = this.refresh.bind(this)); } params() { diff --git a/framework/core/js/forum/src/components/discussion-page.js b/framework/core/js/forum/src/components/discussion-page.js index cceaa54ab..4b61995fe 100644 --- a/framework/core/js/forum/src/components/discussion-page.js +++ b/framework/core/js/forum/src/components/discussion-page.js @@ -31,10 +31,7 @@ export default class DiscussionPage extends Component { // its posts relationship has been loaded (i.e. we've viewed this // discussion before), then we can proceed with displaying it immediately. // If not, we'll make an API request first. - this.currentNear = m.route.param('near') || 0; - var params = this.params(); - params.include = params.include.join(','); - app.store.find('discussions', m.route.param('id'), params).then(this.setupDiscussion.bind(this)); + this.refresh(); if (app.cache.discussionList) { if (!(app.current instanceof DiscussionPage)) { @@ -47,6 +44,18 @@ export default class DiscussionPage extends Component { app.history.push('discussion'); app.current = this; + app.session.on('loggedIn', this.loggedInHandler = this.refresh.bind(this)); + } + + refresh() { + this.currentNear = m.route.param('near') || 0; + this.discussion(null); + + var params = this.params(); + params.include = params.include.join(','); + app.store.find('discussions', m.route.param('id'), params).then(this.setupDiscussion.bind(this)); + + m.redraw(); } params() { @@ -127,6 +136,7 @@ export default class DiscussionPage extends Component { app.pane.disable(); app.composer.minimize(); + app.session.off('loggedIn', this.loggedInHandler); } /** diff --git a/framework/core/js/forum/src/initializers/discussion-controls.js b/framework/core/js/forum/src/initializers/discussion-controls.js index 6d06ed0fa..7aee3afc9 100644 --- a/framework/core/js/forum/src/initializers/discussion-controls.js +++ b/framework/core/js/forum/src/initializers/discussion-controls.js @@ -25,7 +25,7 @@ export default function(app) { } else if (!app.session.user()) { app.modal.show(new LoginModal({ message: 'You must be logged in to do that.', - callback: replyAction.bind(this) + callback: this.replyAction.bind(this) })); } }