Files
malarkey/lib/malarkey_web/live/post_live/index.html.heex
2025-10-29 18:29:57 +00:00

43 lines
1.2 KiB
Plaintext

<.header>
<%= if !!@current_user do %>
<div id="user-greeting">Hi, <%= !!@current_user.fullname || "Sailor" %></div>
<% else %>
<div id="anonymous-greeting">Hello, Sailor!</div>
<% end %>
<:actions>
<.link patch={(!!@current_user && ~p"/posts/new") || "/users/log_in"}>
<button class="inline-flex items-center px-3 py-2 text-sm font-semibold leading-6 text-white rounded-lg bg-brand phx-submit-loading:opacity-75 hover:bg-zinc-700 active:text-white/80">
<%= Heroicons.icon("plus-circle", type: "outline", class: "w-5 h-5 stroke-current mr-1") %>
<span>Add Malarkey</span>
</button>
</.link>
</:actions>
</.header>
<div id="posts" phx-update="prepend">
<%= for post <- @posts do %>
<.live_component
module={MalarkeyWeb.PostLive.PostComponent}
id={post.id}
post={post}
user={@current_user}
/>
<% end %>
</div>
<.modal
:if={@live_action in [:new, :edit]}
id="post-modal"
show
on_cancel={JS.navigate(~p"/posts")}
>
<.live_component
module={MalarkeyWeb.PostLive.FormComponent}
id={@post.id || :new}
title={@page_title}
action={@live_action}
post={@post}
navigate={~p"/posts"}
user={@current_user}
/>
</.modal>