diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 37f663be8..2b92c8cc1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - include Authentication, CurrentRequest, CurrentTimezone, SetPlatform, WriterAffinity + include Authentication, CurrentRequest, CurrentTimezone, SetPlatform, TurboFlash, WriterAffinity stale_when_importmap_changes allow_browser versions: :modern diff --git a/app/controllers/collections/entropy_configurations_controller.rb b/app/controllers/collections/entropy_configurations_controller.rb index 98a2b1b0f..cabdc8c22 100644 --- a/app/controllers/collections/entropy_configurations_controller.rb +++ b/app/controllers/collections/entropy_configurations_controller.rb @@ -4,7 +4,10 @@ class Collections::EntropyConfigurationsController < ApplicationController def update @collection.entropy_configuration.update!(entropy_configuration_params) - render turbo_stream: turbo_stream.replace([ @collection, :entropy_configuration ], partial: "collections/edit/auto_close", locals: { collection: @collection }) + render turbo_stream: [ + turbo_stream.replace([ @collection, :entropy_configuration ], partial: "collections/edit/auto_close", locals: { collection: @collection }), + turbo_stream_flash(notice: "Saved") + ] end private diff --git a/app/controllers/collections/publications_controller.rb b/app/controllers/collections/publications_controller.rb index 2ded7eda2..2043cf60a 100644 --- a/app/controllers/collections/publications_controller.rb +++ b/app/controllers/collections/publications_controller.rb @@ -3,12 +3,18 @@ class Collections::PublicationsController < ApplicationController def create @collection.publish - render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) + render turbo_stream: [ + turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }), + turbo_stream_flash(notice: "Saved") + ] end def destroy @collection.unpublish @collection.reload - render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) + render turbo_stream: [ + turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }), + turbo_stream_flash(notice: "Saved") + ] end end diff --git a/app/controllers/collections/workflows_controller.rb b/app/controllers/collections/workflows_controller.rb index b51114585..7b79baad4 100644 --- a/app/controllers/collections/workflows_controller.rb +++ b/app/controllers/collections/workflows_controller.rb @@ -5,7 +5,10 @@ class Collections::WorkflowsController < ApplicationController def update @collection.update! workflow: @workflow - render turbo_stream: turbo_stream.replace([ @collection, :workflows ], partial: "collections/edit/workflows", locals: { collection: @collection }) + render turbo_stream: [ + turbo_stream.replace([ @collection, :workflows ], partial: "collections/edit/workflows", locals: { collection: @collection }), + turbo_stream_flash(notice: "Saved") + ] end private diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 4dd215d21..0eb049611 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -19,7 +19,7 @@ class CollectionsController < ApplicationController @collection.update! collection_params @collection.accesses.revise granted: grantees, revoked: revokees if grantees_changed? - redirect_to edit_collection_path(@collection), notice: "Changes saved" + redirect_to edit_collection_path(@collection), notice: "Saved" end def destroy diff --git a/app/controllers/concerns/turbo_flash.rb b/app/controllers/concerns/turbo_flash.rb new file mode 100644 index 000000000..7e313a5b9 --- /dev/null +++ b/app/controllers/concerns/turbo_flash.rb @@ -0,0 +1,6 @@ +module TurboFlash + private + def turbo_stream_flash(**flash_options) + turbo_stream.replace(:flash, partial: "layouts/shared/flash", locals: { flash: flash_options }) + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ebd12d36c..1d72a8bb8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,13 +8,7 @@ <%= yield :header %> - <% if notice = flash[:notice] || flash[:alert] %> -
-
- <%= notice %> -
-
- <% end %> + <%= render "layouts/shared/flash" %>
<%= yield %> diff --git a/app/views/layouts/shared/_flash.html.erb b/app/views/layouts/shared/_flash.html.erb new file mode 100644 index 000000000..652e3b130 --- /dev/null +++ b/app/views/layouts/shared/_flash.html.erb @@ -0,0 +1,9 @@ +<%= turbo_frame_tag :flash do %> + <% if notice = flash[:notice] || flash[:alert] %> +
+
+ <%= notice %> +
+
+ <% end %> +<% end %>