Files
something-erlang/lib/something_erlang_web/live/thread_live/show.ex
Rüdiger Diedrich de9afd2907 grover
2022-07-21 18:42:42 +02:00

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