Don't allow upload editing for posts
This commit is contained in:
parent
55858eb9ca
commit
cc4679c9ab
@ -39,7 +39,7 @@ defmodule AggieditWeb.PostLive.FormComponent do
|
|||||||
defp save_upload(socket, %Post{} = post) do
|
defp save_upload(socket, %Post{} = post) do
|
||||||
consume_uploaded_entries(socket, :upload, fn data, upload ->
|
consume_uploaded_entries(socket, :upload, fn data, upload ->
|
||||||
[extension | _] = MIME.extensions(upload.client_type)
|
[extension | _] = MIME.extensions(upload.client_type)
|
||||||
filename = "#{upload.uuid}-#{extension}"
|
filename = "#{upload.uuid}.#{extension}"
|
||||||
|
|
||||||
dest = Path.join("priv/static/uploads", filename)
|
dest = Path.join("priv/static/uploads", filename)
|
||||||
File.cp!(data.path, dest)
|
File.cp!(data.path, dest)
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
<%= textarea f, :body %>
|
<%= textarea f, :body %>
|
||||||
<%= error_tag f, :body %>
|
<%= error_tag f, :body %>
|
||||||
|
|
||||||
|
<%= if !Ecto.assoc_loaded?(@post.upload) do %>
|
||||||
<%= live_file_input @uploads.upload %>
|
<%= live_file_input @uploads.upload %>
|
||||||
|
|
||||||
<%= for upload <- @uploads.upload.entries do %>
|
<%= for upload <- @uploads.upload.entries do %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
@ -26,6 +26,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= else %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="column">
|
||||||
|
<img style="height:80px" src={Routes.static_path(@socket, "/uploads/#{@post.upload.file}")} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= submit "Save", phx_disable_with: "Saving..." %>
|
<%= submit "Save", phx_disable_with: "Saving..." %>
|
||||||
|
@ -22,7 +22,7 @@ defmodule AggieditWeb.PostLive.Index do
|
|||||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||||
socket
|
socket
|
||||||
|> assign(:page_title, "Edit Post")
|
|> assign(:page_title, "Edit Post")
|
||||||
|> assign(:post, Rooms.get_post!(id))
|
|> assign(:post, Rooms.get_post!(id) |> Repo.preload(:upload))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_action(socket, :new, _params) do
|
defp apply_action(socket, :new, _params) do
|
||||||
|
Loading…
Reference in New Issue
Block a user