discourse/app/assets/javascripts/discourse/routes/discovery.js.es6
2015-05-19 12:51:03 -04:00

53 lines
1.4 KiB
JavaScript

/**
The parent route for all discovery routes.
Handles the logic for showing the loading spinners.
**/
import ShowFooter from "discourse/mixins/show-footer";
import OpenComposer from "discourse/mixins/open-composer";
import { scrollTop } from 'discourse/mixins/scroll-top';
const DiscoveryRoute = Discourse.Route.extend(OpenComposer, ShowFooter, {
redirect: function() { return this.redirectIfLoginRequired(); },
beforeModel: function(transition) {
if (transition.intent.url === "/" &&
transition.targetName.indexOf("discovery.top") === -1 &&
Discourse.User.currentProp("should_be_redirected_to_top")) {
Discourse.User.currentProp("should_be_redirected_to_top", false);
this.replaceWith("discovery.top");
}
},
actions: {
loading: function() {
this.controllerFor('discovery').set("loading", true);
return true;
},
loadingComplete: function() {
this.controllerFor('discovery').set('loading', false);
if (!this.session.get('topicListScrollPosition')) {
scrollTop();
}
},
didTransition: function() {
this.controllerFor("discovery")._showFooter();
this.send('loadingComplete');
return true;
},
// clear a pinned topic
clearPin: function(topic) {
topic.clearPin();
},
createTopic: function() {
this.openComposer(this.controllerFor('discovery/topics'));
}
}
});
export default DiscoveryRoute;