summaryrefslogtreecommitdiff
path: root/lib/aggiedit_web/live/post_live/index.html.heex
blob: efb42cb1cc80e950b478bf847aac4ea452bc38b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<h1>@<%= @room.domain %></h1>

<%= if @live_action in [:new, :edit] do %>
  <.modal return_to={Routes.post_index_path(@socket, :index, @room)}>
    <.live_component
      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 %>

<span><%= live_patch "New Post", to: Routes.post_index_path(@socket, :new, @room) %></span>
<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">
      <%= if !is_nil(post.upload) do %>
        <%= live_redirect to: Routes.post_show_path(@socket, :show, @room, post) do %>
          <div class="card-image d-flex justify-content-center" style="width: 100px">
            <img class="fluid-img thumbnail" src={Routes.static_path(@socket, "/uploads/#{post.upload.file}")} />
          </div>
        <% end %>
      <% end %>
      <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>

        <%= 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>
    </div>
  <% end %>
</div>