fix 'go to post' links

This commit is contained in:
byte[] 2019-11-11 12:57:02 -05:00
parent 14d693e2c1
commit e313460917
4 changed files with 14 additions and 4 deletions

View file

@ -7,7 +7,7 @@ defmodule PhilomenaWeb.TopicController do
plug :load_and_authorize_resource, model: Forum, id_name: "forum_id", id_field: "short_name", persisted: true plug :load_and_authorize_resource, model: Forum, id_name: "forum_id", id_field: "short_name", persisted: true
def show(conn, %{"id" => slug}) do def show(conn, %{"id" => slug} = params) do
forum = conn.assigns.forum forum = conn.assigns.forum
topic = topic =
Topic Topic
@ -18,6 +18,16 @@ defmodule PhilomenaWeb.TopicController do
conn = conn |> assign(:topic, topic) conn = conn |> assign(:topic, topic)
%{page_number: page} = conn.assigns.pagination %{page_number: page} = conn.assigns.pagination
page =
with {post_id, _extra} <- Integer.parse(params["post_id"] || ""),
[post] <- Post |> where(id: ^post_id) |> Repo.all()
do
div(post.topic_position, 25) + 1
else
_ ->
page
end
posts = posts =
Post Post
|> where(topic_id: ^conn.assigns.topic.id) |> where(topic_id: ^conn.assigns.topic.id)

View file

@ -26,7 +26,7 @@ h1 Discussion Forums
strong strong
=> link(forum.last_post.topic.title, to: Routes.forum_topic_path(@conn, :show, forum, forum.last_post.topic)) => link(forum.last_post.topic.title, to: Routes.forum_topic_path(@conn, :show, forum, forum.last_post.topic))
br br
=> link("Go to post", to: Routes.forum_topic_path(@conn, :show, forum, forum.last_post.topic, post_id: forum.last_post.id)) => link("Go to post", to: Routes.forum_topic_path(@conn, :show, forum, forum.last_post.topic, post_id: forum.last_post.id) <> "#post_#{forum.last_post.id}")
' by ' by
=> render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: forum.last_post => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: forum.last_post
br br

View file

@ -46,7 +46,7 @@ h1 = @forum.name
td.table--communication-list__stats.hide-mobile = topic.post_count td.table--communication-list__stats.hide-mobile = topic.post_count
td.table--communication-list__last-post td.table--communication-list__last-post
= if topic.last_post do = if topic.last_post do
=> link("Go to post", to: Routes.forum_topic_path(@conn, :show, @forum, topic, post_id: topic.last_post) <> "post_#{topic.last_post.id}") => link("Go to post", to: Routes.forum_topic_path(@conn, :show, @forum, topic, post_id: topic.last_post) <> "#post_#{topic.last_post.id}")
' by ' by
= render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: topic.last_post = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: topic.last_post
br br

View file

@ -13,7 +13,7 @@ div
/ | because: / | because:
/ =<> post.edit_reason / =<> post.edit_reason
div div
- link_path = Routes.forum_topic_path(@conn, :show, @post.topic.forum, @post.topic, post_id: @post.id) <> "post_#{@post.id}" - link_path = Routes.forum_topic_path(@conn, :show, @post.topic.forum, @post.topic, post_id: @post.id) <> "#post_#{@post.id}"
a.communication__interaction title="Link to post" href=link_path a.communication__interaction title="Link to post" href=link_path
i.fa.fa-link> i.fa.fa-link>
' Link ' Link