From ddfab312f73a3f3e15ceb6fec7d350500adb53d6 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Thu, 14 Apr 2022 00:18:01 -0600 Subject: Update UI --- .../live/post_live/form_component.html.heex | 46 ++++++++--------- lib/aggiedit_web/live/post_live/index.ex | 2 +- lib/aggiedit_web/live/post_live/index.html.heex | 59 +++++++++++++--------- 3 files changed, 58 insertions(+), 49 deletions(-) (limited to 'lib/aggiedit_web/live/post_live') 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 %> +
+ <%= label f, :title %> + <%= text_input f, :title, class: "form-control" %> + <%= error_tag f, :title %> +
- <%= label f, :body %> - <%= textarea f, :body %> - <%= error_tag f, :body %> +
+ <%= label f, :body %> + <%= textarea f, :body, class: "form-control" %> + <%= error_tag f, :body %> +
- <%= if !Ecto.assoc_loaded?(@post.upload) do %> - <%= live_file_input @uploads.upload %> - <%= for upload <- @uploads.upload.entries do %> -
-
- <%= live_img_preview upload, height: 80 %> +
+ <%= if !Ecto.assoc_loaded?(@post.upload) do %> + <%= live_file_input @uploads.upload %> + <%= for upload <- @uploads.upload.entries do %> +
+
+ <%= live_img_preview upload, height: 80 %> +
-
+ <% end %> <% end %> - <% else %> - <%= if !is_nil(@post.upload) do %> -
-
- -
-
- <% end %> - <% end %> +
-
- <%= submit "Save", phx_disable_with: "Saving..." %> +
+ <%= submit "Save", phx_disable_with: "Saving...", class: "btn btn-primary" %>
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 @@ -

Listing Posts

+

@<%= @room.domain %>

<%= if @live_action in [:new, :edit] do %> <.modal return_to={Routes.post_index_path(@socket, :index, @room)}> @@ -14,29 +14,40 @@ <% end %> - - - - - +<%= live_patch "New Post", to: Routes.post_index_path(@socket, :new, @room) %> +<%= for post <- @posts do %> +
+ <%= if !is_nil(post.upload) do %> + <%= live_redirect to: Routes.post_show_path(@socket, :show, @room, post) do %> +
+ +
+ <% end %> + <% end %> +
+ <%= live_redirect to: Routes.post_show_path(@socket, :show, @room, post) do %> +

<%= post.title %>

+ <% end %> +
aggie/<%= post.user.username %>
+

<%= post.body %>

-
- - - - <%= for post <- @posts do %> - - - + <%= if Aggiedit.Roles.guard?(@current_user, :edit, post) && Aggiedit.Roles.guard?(@current_user, :edit, post) do %> + <%= live_patch "Edit", to: Routes.post_index_path(@socket, :edit, @room, post) %> + <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: post.id %> + <% end %> + + + +<% end %> -<%= live_patch "New Post", to: Routes.post_index_path(@socket, :new, @room) %> -- cgit v1.2.3-70-g09d2
TitleBody
<%= post.title %><%= post.body %>