grover
This commit is contained in:
@ -3,21 +3,49 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
|
||||
on_mount SomethingErlangWeb.UserLiveAuth
|
||||
|
||||
alias SomethingErlang.Forums
|
||||
alias SomethingErlang.Grover
|
||||
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
socket |> IO.inspect
|
||||
def mount(%{"id" => id} = _params, _session, socket) do
|
||||
Grover.mount(self(), socket.assigns.current_user, id)
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
def handle_params(%{"id" => id, "page" => page}, _, socket) do
|
||||
thread = Grover.get_thread!(self(), id, page |> String.to_integer())
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:thread, Forums.get_thread!(id))}
|
||||
|> assign(:thread, thread)}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Thread"
|
||||
defp page_title(:edit), do: "Edit Thread"
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
{:noreply, push_redirect(socket,
|
||||
to: Routes.thread_show_path(socket, :show, id, page: 1))}
|
||||
end
|
||||
|
||||
def post(assigns) do
|
||||
~H"""
|
||||
<div class="post">
|
||||
<.user info={@author} />
|
||||
<article class="grow-1 w-full">
|
||||
<%= raw @article %>
|
||||
</article>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def user(assigns) do
|
||||
~H"""
|
||||
<aside class="userinfo shrink-0 w-[13em]">
|
||||
<h3><%= @info.name %></h3>
|
||||
<div class="title">
|
||||
<%= raw @info.title %>
|
||||
</div>
|
||||
</aside>
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,3 @@
|
||||
<h1>Show Thread</h1>
|
||||
|
||||
<%= if @live_action in [:edit] do %>
|
||||
<.modal return_to={Routes.thread_show_path(@socket, :show, @thread)}>
|
||||
<.live_component
|
||||
@ -13,19 +11,18 @@
|
||||
</.modal>
|
||||
<% end %>
|
||||
|
||||
<ul>
|
||||
<h2>
|
||||
<%= @thread.title %>
|
||||
</h2>
|
||||
|
||||
<li>
|
||||
<strong>Title:</strong>
|
||||
<%= @thread.title %>
|
||||
</li>
|
||||
<div class="thread my-8">
|
||||
<%= for post <- @thread.posts do %>
|
||||
<.post author={post.userinfo} article={post.postbody} />
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<li>
|
||||
<strong>Thread:</strong>
|
||||
<%= @thread.thread_id %>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<span><%= live_patch "Edit", to: Routes.thread_show_path(@socket, :edit, @thread), class: "button" %></span> |
|
||||
<span><%= live_redirect "Back", to: Routes.thread_index_path(@socket, :index) %></span>
|
||||
<span><%= @thread.page %></span>
|
||||
<span><%= live_redirect "Next Page", class: "link",
|
||||
to: Routes.thread_show_path(@socket, :show, @thread.id, page: @thread.page+1) %></span>
|
||||
|
Reference in New Issue
Block a user