Aggiedit/lib/aggiedit_web/live/post_live/index.html.heex

59 lines
2.5 KiB
Plaintext
Raw Permalink Normal View History

2022-04-14 02:18:01 -04:00
<h1>@<%= @room.domain %></h1>
<%= if @live_action in [:new, :edit] do %>
<.modal return_to={Routes.post_index_path(@socket, :index, @room)}>
<.live_component
2022-04-07 17:52:32 -04:00
current_user={@current_user}
module={AggieditWeb.PostLive.FormComponent}
id={@post.id || :new}
title={@page_title}
action={@live_action}
post={@post}
return_to={Routes.post_index_path(@socket, :index, @room)}
/>
</.modal>
<% end %>
2022-04-14 02:18:01 -04:00
<span><%= live_patch "New Post", to: Routes.post_index_path(@socket, :new, @room) %></span>
2022-04-14 13:43:34 -04:00
<div id="posts" phx-update="prepend">
<%= for post <- @posts do %>
<div id={"post-#{post.id}"} class="card d-flex flex-row align-items-center p-2 m-2 shadow">
<div class="d-flex flex-column m-2">
<%=
has_vote = Map.has_key?(@votes, post.id)
is_upvote = has_vote && @votes[post.id].is_up
""
%>
<div class="d-flex">
<span><%= link "", to: "#", phx_click: "upvote", phx_value_id: post.id, class: "bi bi-arrow-up-circle#{if has_vote && is_upvote, do: "-fill", else: ""}" %></span>
</div>
<div class="d-flex">
<%= post.score %>
</div>
<div class="d-flex">
<span><%= link "", to: "#", phx_click: "downvote", phx_value_id: post.id, class: "bi bi-arrow-down-circle#{if has_vote && !is_upvote, do: "-fill", else: ""}" %></span>
</div>
</div>
<div class="m-2 card-image d-flex justify-content-center" style="width: 100px">
<%= if !is_nil(post.upload) do %>
<%= live_redirect to: Routes.post_show_path(@socket, :show, @room, post) do %>
2022-04-14 13:43:34 -04:00
<img class="fluid-img thumbnail" src={Routes.static_path(@socket, "/uploads/#{post.upload.file}")} />
<% end %>
2022-04-14 13:43:34 -04:00
<% end %>
</div>
2022-04-14 13:43:34 -04:00
<div class="card-body">
<%= live_redirect to: Routes.post_show_path(@socket, :show, @room, post) do %>
<h4 class="card-title"><%= post.title %></h4>
<% end %>
<h6 class="card-subtitle mb-2"><span class="text-muted">aggie/</span><%= post.user.username %></h6>
<p class="card-text"><%= post.body %></p>
2022-04-14 13:43:34 -04:00
<%= if Aggiedit.Roles.guard?(@current_user, :edit, post) && Aggiedit.Roles.guard?(@current_user, :edit, post) do %>
<span><%= live_patch "Edit", to: Routes.post_index_path(@socket, :edit, @room, post) %></span>
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: post.id %></span>
<% end %>
</div>
2022-04-14 02:18:01 -04:00
</div>
2022-04-14 13:43:34 -04:00
<% end %>
</div>