diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-08 13:01:24 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-08 13:01:24 -0600 |
commit | cc4679c9ab0bc2607179a26556e3b381a7a2533c (patch) | |
tree | 98ce246d8aa775fa64562617b18f5268db35de5c | |
parent | 55858eb9ca9d93c8ffa8fafd4c5d965b602326be (diff) | |
download | aggiedit-cc4679c9ab0bc2607179a26556e3b381a7a2533c.tar.gz aggiedit-cc4679c9ab0bc2607179a26556e3b381a7a2533c.zip |
Don't allow upload editing for posts
-rw-r--r-- | lib/aggiedit_web/live/post_live/form_component.ex | 2 | ||||
-rw-r--r-- | lib/aggiedit_web/live/post_live/form_component.html.heex | 15 | ||||
-rw-r--r-- | lib/aggiedit_web/live/post_live/index.ex | 2 |
3 files changed, 13 insertions, 6 deletions
diff --git a/lib/aggiedit_web/live/post_live/form_component.ex b/lib/aggiedit_web/live/post_live/form_component.ex index 532950c..66f2477 100644 --- a/lib/aggiedit_web/live/post_live/form_component.ex +++ b/lib/aggiedit_web/live/post_live/form_component.ex @@ -39,7 +39,7 @@ defmodule AggieditWeb.PostLive.FormComponent do defp save_upload(socket, %Post{} = post) do consume_uploaded_entries(socket, :upload, fn data, upload -> [extension | _] = MIME.extensions(upload.client_type) - filename = "#{upload.uuid}-#{extension}" + filename = "#{upload.uuid}.#{extension}" dest = Path.join("priv/static/uploads", filename) File.cp!(data.path, dest) 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 695a90a..2f0738e 100644 --- a/lib/aggiedit_web/live/post_live/form_component.html.heex +++ b/lib/aggiedit_web/live/post_live/form_component.html.heex @@ -17,12 +17,19 @@ <%= textarea f, :body %> <%= error_tag f, :body %> - <%= live_file_input @uploads.upload %> - - <%= for upload <- @uploads.upload.entries do %> + <%= 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> + <% end %> + <%= else %> <div class="row"> <div class="column"> - <%= live_img_preview upload, height: 80 %> + <img style="height:80px" src={Routes.static_path(@socket, "/uploads/#{@post.upload.file}")} /> </div> </div> <% end %> diff --git a/lib/aggiedit_web/live/post_live/index.ex b/lib/aggiedit_web/live/post_live/index.ex index 8ec98c7..7f3ac65 100644 --- a/lib/aggiedit_web/live/post_live/index.ex +++ b/lib/aggiedit_web/live/post_live/index.ex @@ -22,7 +22,7 @@ defmodule AggieditWeb.PostLive.Index do defp apply_action(socket, :edit, %{"id" => id}) do socket |> assign(:page_title, "Edit Post") - |> assign(:post, Rooms.get_post!(id)) + |> assign(:post, Rooms.get_post!(id) |> Repo.preload(:upload)) end defp apply_action(socket, :new, _params) do |