more stuff
This commit is contained in:
@ -30,7 +30,7 @@
|
||||
</div>
|
||||
</header>
|
||||
<main class="px-4 py-20 sm:px-6 lg:px-8">
|
||||
<div class="mx-auto max-w-2xl">
|
||||
<div class="mx-auto">
|
||||
<.flash kind={:info} title="Success!" flash={@flash} />
|
||||
<.flash kind={:error} title="Error!" flash={@flash} />
|
||||
<.flash
|
||||
|
@ -11,7 +11,7 @@
|
||||
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
|
||||
</script>
|
||||
</head>
|
||||
<body class="bg-white antialiased">
|
||||
<body class="antialiased">
|
||||
<ul class="flex justify-end gap-2">
|
||||
<%= if @current_user do %>
|
||||
<li>
|
||||
|
@ -3,10 +3,32 @@ defmodule SomethingErlangWeb.ThreadLive do
|
||||
|
||||
alias SomethingErlang.Grover
|
||||
|
||||
def render(%{thread: _} = assigns) do
|
||||
~H"""
|
||||
<h2>
|
||||
<%= raw(@thread.title) %>
|
||||
</h2>
|
||||
|
||||
<div class="thread my-8">
|
||||
<.pagination thread={@thread} />
|
||||
|
||||
<%= for %{userinfo: author, postdate: date, postbody: article} <- @thread.posts do %>
|
||||
<.post author={author} date={date}>
|
||||
<%= raw(article) %>
|
||||
</.post>
|
||||
<% end %>
|
||||
|
||||
<.pagination thread={@thread} />
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<h1>Threads!</h1>
|
||||
<pre class="whitespace-pre-wrap break-all">
|
||||
<h2>
|
||||
Threads!
|
||||
</h2>
|
||||
<pre class="whitespace-pre-wrap">
|
||||
<%= inspect(@current_user) %>
|
||||
</pre>
|
||||
"""
|
||||
@ -17,7 +39,7 @@ defmodule SomethingErlangWeb.ThreadLive do
|
||||
<div class="post">
|
||||
<.user info={@author} />
|
||||
<article class="postbody">
|
||||
<%= raw(@article) %>
|
||||
<%= render_slot(@inner_block) %>
|
||||
</article>
|
||||
<.toolbar date={@date} />
|
||||
</div>
|
||||
@ -44,7 +66,36 @@ defmodule SomethingErlangWeb.ThreadLive do
|
||||
end
|
||||
|
||||
def pagination(assigns) do
|
||||
%{page: page_number, page_count: page_count} = assigns.thread
|
||||
~H"""
|
||||
<div class="navbar my-4 bg-base-200">
|
||||
<div class="flex-1"></div>
|
||||
<div class="pagination flex-none btn-group grid grid-cols-5">
|
||||
<%= for btn <- buttons(@thread) do %>
|
||||
<.link
|
||||
class={["btn btn-sm btn-ghost", btn.special]}
|
||||
navigate={~p"/thread/#{@thread.id}?page=#{btn.page}"}
|
||||
>
|
||||
<%= case btn.label do %>
|
||||
<% "«" -> %>
|
||||
<Heroicons.chevron_double_left mini /><%= btn.page %>
|
||||
<% "‹" -> %>
|
||||
<Heroicons.chevron_left mini /><%= btn.page %>
|
||||
<% "›" -> %>
|
||||
<%= btn.page %><Heroicons.chevron_right mini />
|
||||
<% "»" -> %>
|
||||
<%= btn.page %><Heroicons.chevron_double_right mini />
|
||||
<% _ -> %>
|
||||
<%= btn.page %>
|
||||
<% end %>
|
||||
</.link>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp buttons(thread) do
|
||||
%{page: page_number, page_count: page_count} = thread
|
||||
|
||||
first_page_disabled_button = if page_number == 1, do: " btn-disabled", else: ""
|
||||
last_page_disabled_button = if page_number == page_count, do: " btn-disabled", else: ""
|
||||
@ -53,41 +104,17 @@ defmodule SomethingErlangWeb.ThreadLive do
|
||||
prev_button_target = if page_number > 1, do: page_number - 1, else: 1
|
||||
next_button_target = if page_number < page_count, do: page_number + 1, else: page_count
|
||||
|
||||
buttons = [
|
||||
[
|
||||
%{label: "«", page: 1, special: "" <> first_page_disabled_button},
|
||||
%{label: "‹", page: prev_button_target, special: "" <> first_page_disabled_button},
|
||||
%{label: "#{page_number}", page: page_number, special: active_page_button},
|
||||
%{label: "›", page: next_button_target, special: "" <> last_page_disabled_button},
|
||||
%{label: "»", page: page_count, special: "" <> last_page_disabled_button}
|
||||
]
|
||||
|
||||
~H"""
|
||||
<div class="navbar my-4 bg-base-200">
|
||||
<div class="flex-1"></div>
|
||||
<div class="pagination flex-none btn-group grid grid-cols-5">
|
||||
<%= for btn <- buttons do %>
|
||||
<%= live_redirect class: "btn btn-sm btn-ghost" <> btn.special,
|
||||
to: ~p"/thread/#{@thread.id}?page=#{btn.page}" do %>
|
||||
<%= case btn.label do %>
|
||||
<% "«" -> %>
|
||||
<Icons.chevron_left_double /><%= btn.page %>
|
||||
<% "‹" -> %>
|
||||
<Icons.chevron_left /><%= btn.page %>
|
||||
<% "›" -> %>
|
||||
<%= btn.page %><Icons.chevron_right />
|
||||
<% "»" -> %>
|
||||
<%= btn.page %><Icons.chevron_right_double />
|
||||
<% _ -> %>
|
||||
<%= btn.page %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
Grover.mount(socket.assigns.current_user)
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@ -102,7 +129,13 @@ defmodule SomethingErlangWeb.ThreadLive do
|
||||
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
params = %{page: 1}
|
||||
{:noreply, push_redirect(socket, to: ~p"/thread/#{id}?#{params}")}
|
||||
|
||||
{:noreply,
|
||||
push_patch(
|
||||
socket,
|
||||
to: ~p"/thread/#{id}?#{params}",
|
||||
replace: true
|
||||
)}
|
||||
end
|
||||
|
||||
def handle_params(%{}, _, socket) do
|
||||
|
Reference in New Issue
Block a user