52 lines
1.2 KiB
Elixir
52 lines
1.2 KiB
Elixir
defmodule SomethingErlangWeb.ThreadLive.Show do
|
|
use SomethingErlangWeb, :live_view
|
|
on_mount SomethingErlangWeb.UserLiveAuth
|
|
|
|
alias SomethingErlang.Forums
|
|
alias SomethingErlang.Grover
|
|
|
|
require Logger
|
|
|
|
@impl true
|
|
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, "page" => page}, _, socket) do
|
|
thread = Grover.get_thread!(self(), id, page |> String.to_integer())
|
|
{:noreply,
|
|
socket
|
|
|> assign(:thread, thread)}
|
|
end
|
|
|
|
@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
|