Add support for the '/p/:post_id' route on the client-side

This commit is contained in:
Régis Hanol
2018-03-24 02:44:39 +01:00
parent 3a58dc0858
commit c5c1d8e180
4 changed files with 34 additions and 16 deletions
@@ -5,6 +5,8 @@ export default function() {
this.route('about', { path: '/about', resetNamespace: true });
this.route('post', { path: '/p/:id' });
// Topic routes
this.route('topic', { path: '/t/:slug/:id', resetNamespace: true }, function() {
this.route('fromParams', { path: '/' });
@@ -0,0 +1,9 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
beforeModel({ params }) {
return ajax(`/p/${params.post.id}`).then(t => {
this.transitionTo("topic.fromParamsNear", t.slug, t.id, t.current_post_number);
});
}
});
+9
View File
@@ -50,6 +50,7 @@ class TopicViewSerializer < ApplicationSerializer
:unpinned,
:pinned,
:details,
:current_post_number,
:highest_post_number,
:last_read_post_number,
:last_read_post_id,
@@ -172,6 +173,14 @@ class TopicViewSerializer < ApplicationSerializer
object.topic_user.present?
end
def current_post_number
[object.post_number, object.highest_post_number].min
end
def include_current_post_number?
object.highest_post_number.present?
end
def highest_post_number
object.highest_post_number
end