REFACTOR: topic-from-params route (#7689)

This commit is contained in:
Joffrey JAFFEUX 2019-06-04 15:51:22 +02:00 committed by GitHub
parent f7a2648694
commit 4201329f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,9 +17,8 @@ export default Discourse.Route.extend({
params = params || {}; params = params || {};
params.track_visit = true; params.track_visit = true;
const self = this, const topic = this.modelFor("topic"),
topic = this.modelFor("topic"), postStream = topic.postStream,
postStream = topic.get("postStream"),
topicController = this.controllerFor("topic"), topicController = this.controllerFor("topic"),
composerController = this.controllerFor("composer"); composerController = this.controllerFor("composer");
@ -32,7 +31,7 @@ export default Discourse.Route.extend({
postStream postStream
.refresh(params) .refresh(params)
.then(function() { .then(() => {
// TODO we are seeing errors where closest post is null and this is exploding // TODO we are seeing errors where closest post is null and this is exploding
// we need better handling and logging for this condition. // we need better handling and logging for this condition.
@ -40,22 +39,20 @@ export default Discourse.Route.extend({
const closestPost = postStream.closestPostForPostNumber( const closestPost = postStream.closestPostForPostNumber(
params.nearPost || 1 params.nearPost || 1
); );
const closest = closestPost.get("post_number"); const closest = closestPost.post_number;
topicController.setProperties({ topicController.setProperties({
"model.currentPost": closest, "model.currentPost": closest,
enteredIndex: topic enteredIndex: topic.postStream.progressIndexOfPost(closestPost),
.get("postStream")
.progressIndexOfPost(closestPost),
enteredAt: new Date().getTime().toString() enteredAt: new Date().getTime().toString()
}); });
topicController.subscribe(); topicController.subscribe();
// Highlight our post after the next render // Highlight our post after the next render
Ember.run.scheduleOnce("afterRender", function() { Ember.run.scheduleOnce("afterRender", () =>
self.appEvents.trigger("post:highlight", closest); this.appEvents.trigger("post:highlight", closest)
}); );
const opts = {}; const opts = {};
if (document.location.hash && document.location.hash.length) { if (document.location.hash && document.location.hash.length) {
@ -63,13 +60,13 @@ export default Discourse.Route.extend({
} }
DiscourseURL.jumpToPost(closest, opts); DiscourseURL.jumpToPost(closest, opts);
if (!Ember.isEmpty(topic.get("draft"))) { if (!Ember.isEmpty(topic.draft)) {
composerController.open({ composerController.open({
draft: Draft.getLocal(topic.get("draft_key"), topic.get("draft")), draft: Draft.getLocal(topic.draft_key, topic.draft),
draftKey: topic.get("draft_key"), draftKey: topic.draft_key,
draftSequence: topic.get("draft_sequence"), draftSequence: topic.draft_sequence,
topic: topic, ignoreIfChanged: true,
ignoreIfChanged: true topic
}); });
} }
}) })