summaryrefslogtreecommitdiff
path: root/lib/aggiedit_web/live
diff options
context:
space:
mode:
Diffstat (limited to 'lib/aggiedit_web/live')
-rw-r--r--lib/aggiedit_web/live/live_helpers.ex2
-rw-r--r--lib/aggiedit_web/live/post_live/form_component.html.heex46
-rw-r--r--lib/aggiedit_web/live/post_live/index.ex2
-rw-r--r--lib/aggiedit_web/live/post_live/index.html.heex59
4 files changed, 59 insertions, 50 deletions
diff --git a/lib/aggiedit_web/live/live_helpers.ex b/lib/aggiedit_web/live/live_helpers.ex
index a8d067e..b5c81b9 100644
--- a/lib/aggiedit_web/live/live_helpers.ex
+++ b/lib/aggiedit_web/live/live_helpers.ex
@@ -38,7 +38,7 @@ defmodule AggieditWeb.LiveHelpers do
<div id="modal" class="phx-modal fade-in" phx-remove={hide_modal()}>
<div
id="modal-content"
- class="phx-modal-content fade-in-scale"
+ class="phx-modal-content shadow-lg fade-in-scale rounded bg-white"
phx-click-away={JS.dispatch("click", to: "#close")}
phx-window-keydown={JS.dispatch("click", to: "#close")}
phx-key="escape"
diff --git a/lib/aggiedit_web/live/post_live/form_component.html.heex b/lib/aggiedit_web/live/post_live/form_component.html.heex
index b0a798e..aa24a3c 100644
--- a/lib/aggiedit_web/live/post_live/form_component.html.heex
+++ b/lib/aggiedit_web/live/post_live/form_component.html.heex
@@ -9,35 +9,33 @@
phx-change="validate"
phx-submit="save">
- <%= label f, :title %>
- <%= textarea f, :title %>
- <%= error_tag f, :title %>
+ <div class="form-group">
+ <%= label f, :title %>
+ <%= text_input f, :title, class: "form-control" %>
+ <%= error_tag f, :title %>
+ </div>
- <%= label f, :body %>
- <%= textarea f, :body %>
- <%= error_tag f, :body %>
+ <div class="form-group mt-2">
+ <%= label f, :body %>
+ <%= textarea f, :body, class: "form-control" %>
+ <%= error_tag f, :body %>
+ </div>
- <%= if !Ecto.assoc_loaded?(@post.upload) do %>
- <%= live_file_input @uploads.upload %>
- <%= for upload <- @uploads.upload.entries do %>
- <div class="row">
- <div class="column">
- <%= live_img_preview upload, height: 80 %>
+ <div class="form-group mt-2">
+ <%= if !Ecto.assoc_loaded?(@post.upload) do %>
+ <%= live_file_input @uploads.upload %>
+ <%= for upload <- @uploads.upload.entries do %>
+ <div class="row">
+ <div class="column">
+ <%= live_img_preview upload, height: 80 %>
+ </div>
</div>
- </div>
+ <% end %>
<% end %>
- <% else %>
- <%= if !is_nil(@post.upload) do %>
- <div class="row">
- <div class="column">
- <img style="height:80px" src={Routes.static_path(@socket, "/uploads/#{@post.upload.file}")} />
- </div>
- </div>
- <% end %>
- <% end %>
+ </div>
- <div>
- <%= submit "Save", phx_disable_with: "Saving..." %>
+ <div class="mt-2">
+ <%= submit "Save", phx_disable_with: "Saving...", class: "btn btn-primary" %>
</div>
</.form>
</div>
diff --git a/lib/aggiedit_web/live/post_live/index.ex b/lib/aggiedit_web/live/post_live/index.ex
index 6972a44..57ae727 100644
--- a/lib/aggiedit_web/live/post_live/index.ex
+++ b/lib/aggiedit_web/live/post_live/index.ex
@@ -10,7 +10,7 @@ defmodule AggieditWeb.PostLive.Index do
def mount(%{"room_id" => _room_id} = params, session, socket) do
{:ok, socket} = assign_socket_room_and_user_or_error(params, session, socket)
case socket.assigns do
- %{:room => room} -> {:ok, assign(socket, %{:posts => room |> Repo.preload(:posts) |> Map.get(:posts)})}
+ %{:room => room} -> {:ok, assign(socket, %{:posts => room |> Repo.preload(posts: [:user, :upload]) |> Map.get(:posts)})}
_ -> {:ok, socket}
end
end
diff --git a/lib/aggiedit_web/live/post_live/index.html.heex b/lib/aggiedit_web/live/post_live/index.html.heex
index 329f84c..7532685 100644
--- a/lib/aggiedit_web/live/post_live/index.html.heex
+++ b/lib/aggiedit_web/live/post_live/index.html.heex
@@ -1,4 +1,4 @@
-<h1>Listing Posts</h1>
+<h1>@<%= @room.domain %></h1>
<%= if @live_action in [:new, :edit] do %>
<.modal return_to={Routes.post_index_path(@socket, :index, @room)}>
@@ -14,29 +14,40 @@
</.modal>
<% end %>
-<table>
- <thead>
- <tr>
- <th>Title</th>
- <th>Body</th>
+<span><%= live_patch "New Post", to: Routes.post_index_path(@socket, :new, @room) %></span>
+<%= for post <- @posts do %>
+ <div 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>
- <th></th>
- </tr>
- </thead>
- <tbody id="posts">
- <%= for post <- @posts do %>
- <tr id={"post-#{post.id}"}>
- <td><%= post.title %></td>
- <td><%= post.body %></td>
+ <%= 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>
+<!--
+ <div class=>
+ </div>
+ <tr id={"post-#{post.id}"}>
+ <td><%= post.title %></td>
+ <td><%= post.body %></td>
- <td>
- <span><%= live_redirect "Show", to: Routes.post_show_path(@socket, :show, @room, post) %></span>
- <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, data: [confirm: "Are you sure?"] %></span>
- </td>
- </tr>
- <% end %>
- </tbody>
-</table>
+ <td>
+ <span></span>
+ </td>
+ </tr>
+ -->
+<% end %>
-<span><%= live_patch "New Post", to: Routes.post_index_path(@socket, :new, @room) %></span>