diff --git a/app/controllers/collections/publications_controller.rb b/app/controllers/collections/publications_controller.rb index feb5ae4b7..2ded7eda2 100644 --- a/app/controllers/collections/publications_controller.rb +++ b/app/controllers/collections/publications_controller.rb @@ -3,11 +3,12 @@ class Collections::PublicationsController < ApplicationController def create @collection.publish - redirect_to edit_collection_path(@collection) + render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) end def destroy @collection.unpublish - redirect_to edit_collection_path(@collection) + @collection.reload + render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) end end diff --git a/app/views/collections/edit/_publication.html.erb b/app/views/collections/edit/_publication.html.erb index 72f315b8d..921cd6fe2 100644 --- a/app/views/collections/edit/_publication.html.erb +++ b/app/views/collections/edit/_publication.html.erb @@ -1,54 +1,55 @@ -
- Public link -

Turn on the Public link to share this collection with anyone in the world. They won’t need to log in and they won’t be able to see anything else in Fizzy.

+<%= turbo_frame_tag @collection, :publication do %> +
+ Public link +

Turn on the Public link to share this collection with anyone in the world. They won’t need to log in and they won’t be able to see anything else in Fizzy.

- <% if collection.published? %> -
-
- <%= icon_tag "lock" %> - - <%= icon_tag "world" %> -
+ <% if collection.published? %> +
+
+ <%= icon_tag "lock" %> + + <%= icon_tag "world" %> +
-
- <%= text_field_tag :publication_url, published_collection_url(collection), disabled: true, class: "full-width input fill-white" %> -
- <%= button_to_copy_to_clipboard(published_collection_url(collection)) do %> - <%= icon_tag "copy-paste" %> - Copy public link +
+ <%= text_field_tag :publication_url, published_collection_url(collection), disabled: true, class: "full-width input fill-white" %> +
+ <%= button_to_copy_to_clipboard(published_collection_url(collection)) do %> + <%= icon_tag "copy-paste" %> + Copy public link + <% end %> +
+
+ Add an optional description to the public page +
+ <%= form_with model: collection, class: "txt-align-start", data: { controller: "form" } do |form| %> + <%= form.rich_textarea :public_description, class: "rich-text-content txt-small", + placeholder: "Add a public note about this collection…", + data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %> + <%= form.button "Save changes", type: :submit, class: "btn txt-small" %> <% end %>
- Add an optional description to the public page -
- <%= form_with model: collection, class: "txt-align-start", data: { controller: "form" } do |form| %> - <%= form.rich_textarea :public_description, class: "rich-text-content txt-small", - placeholder: "Add a public note about this collection…", - data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %> - <%= form.button "Save changes", type: :submit, class: "btn txt-small" %> - <% end %> + <% else %> +
+
+ <%= icon_tag "lock" %> + + <%= icon_tag "world" %> +
-
- <% else %> -
-
- <%= icon_tag "lock" %> - - <%= icon_tag "world" %> -
-
- <% end %> -
- + <% end %> +
+<% end %> diff --git a/test/controllers/collections/publications_controller_test.rb b/test/controllers/collections/publications_controller_test.rb index 2bd9ec1dc..da24c22da 100644 --- a/test/controllers/collections/publications_controller_test.rb +++ b/test/controllers/collections/publications_controller_test.rb @@ -13,7 +13,7 @@ class Collections::PublicationsControllerTest < ActionDispatch::IntegrationTest post collection_publication_path(@collection) end - assert_redirected_to edit_collection_path(@collection) + assert_turbo_stream action: :replace, target: dom_id(@collection, :publication) end test "unpublish a collection" do @@ -24,6 +24,6 @@ class Collections::PublicationsControllerTest < ActionDispatch::IntegrationTest delete collection_publication_path(@collection) end - assert_redirected_to edit_collection_path(@collection) + assert_turbo_stream action: :replace, target: dom_id(@collection, :publication) end end