From 763ea5331b1977dd949c776215f2c7719f81ee9a Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Wed, 20 Apr 2022 16:03:17 -0600 Subject: Initial chat box; man phoenix does not have the best docs --- lib/aggiedit_web/live/post_live/show.ex | 6 +- lib/aggiedit_web/live/post_live/show.html.heex | 84 +++++++++++++++++++++----- 2 files changed, 71 insertions(+), 19 deletions(-) (limited to 'lib/aggiedit_web/live') diff --git a/lib/aggiedit_web/live/post_live/show.ex b/lib/aggiedit_web/live/post_live/show.ex index 9d8f86c..69cd6c5 100644 --- a/lib/aggiedit_web/live/post_live/show.ex +++ b/lib/aggiedit_web/live/post_live/show.ex @@ -15,10 +15,10 @@ defmodule AggieditWeb.PostLive.Show do post = Rooms.get_post!(id) |> Repo.preload(:upload) if Roles.guard?(socket.assigns.current_user, socket.assigns.live_action, post) do - {:noreply, - socket + socket = (if socket.assigns.live_action == :show, do: push_event(socket, "initial-post", %{:id => post.id}), else: socket) |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:post, post)} + |> assign(:post, post) + {:noreply, socket} else {:noreply, socket |> put_flash(:error, "You don't have permission to do that.") |> redirect(to: Routes.post_show_path(socket, :show, socket.assigns.room, post))} end diff --git a/lib/aggiedit_web/live/post_live/show.html.heex b/lib/aggiedit_web/live/post_live/show.html.heex index 107a3a6..8f91fda 100644 --- a/lib/aggiedit_web/live/post_live/show.html.heex +++ b/lib/aggiedit_web/live/post_live/show.html.heex @@ -1,4 +1,37 @@ -

Show Post

+ +
+
+
+

<%= @post.title %>

+
+
+ <%= if Ecto.assoc_loaded?(@post.upload) && !is_nil(@post.upload) do %> + + <% end %> +
+
+ <%= @post.body %> +
+ <%= if Aggiedit.Roles.guard?(@current_user, :edit, @post) do %> + <%= live_patch "Edit", to: Routes.post_show_path(@socket, :edit, @room, @post), class: "button" %> | + <% end %> + <%= live_redirect "Back", to: Routes.post_index_path(@socket, :index, @room) %> +
+
+ + +
+
+
+
+
+
    +
+
+
+
+
+
<%= if @live_action in [:edit] do %> <.modal return_to={Routes.post_show_path(@socket, :show, @room, @post)}> @@ -14,24 +47,43 @@ <% end %> -