set default sources for image view page if none are available

This commit is contained in:
SeinopSys 2021-10-10 01:40:08 +02:00 committed by Luna D
parent 880d27ac1e
commit adc77429f6
No known key found for this signature in database
GPG key ID: 4B1C63448394F688
2 changed files with 6 additions and 3 deletions

View file

@ -81,6 +81,7 @@ defmodule PhilomenaWeb.ImageController do
image_changeset =
image
|> update_in([:sources], &sources_for_edit/1)
|> Images.change_image()
watching = Images.subscribed?(image, conn.assigns.current_user)
@ -109,7 +110,7 @@ defmodule PhilomenaWeb.ImageController do
def new(conn, _params) do
changeset =
%Image{sources: [%Source{}]}
%Image{sources: sources_for_edit()}
|> Images.change_image()
render(conn, "new.html", title: "New Image", changeset: changeset)
@ -218,4 +219,8 @@ defmodule PhilomenaWeb.ImageController do
|> assign(:source_change_count, source_changes)
end
end
defp sources_for_edit(), do: [%Source{}]
defp sources_for_edit([]), do: sources_for_edit()
defp source_for_edit(sources), do: sources
end

View file

@ -43,8 +43,6 @@
span.js-max-source-count> 10
' source URLs. Leave any sources you don't want to use blank.
= inputs_for f, :sources, [as: "image[old_sources]"], fn fs ->
= hidden_input fs, :source
= inputs_for f, :sources, fn fs ->
.field.js-image-source.field--inline.flex--no-wrap.flex--centered
= text_input fs, :source, class: "input flex__grow js-source-url", placeholder: "Source URL"