From 581aa76b4939ad0e1be5a4a0ec8a4c4e67f36164 Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 1 Sep 2025 19:54:28 +0000 Subject: [PATCH] refactored3 --- app/controllers/notification_controller.rb | 6 ++---- app/javascript/controllers/flash_controller.js | 4 ++-- app/views/layouts/components/_flash.html.erb | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/notification_controller.rb b/app/controllers/notification_controller.rb index 011acb4..70aa0d9 100644 --- a/app/controllers/notification_controller.rb +++ b/app/controllers/notification_controller.rb @@ -1,9 +1,7 @@ COUNT ||= 0 class NotificationController < ApplicationController - def index - logger.info 'index' - end + def index; end def show_notice flash.alert = %w[titi toto] if params[:multiple] == 'true' @@ -17,7 +15,7 @@ class NotificationController < ApplicationController def turbo_notice COUNT += 1 - # TODO: render_stream (partial + flash -> flash.now + optional replace|append) + # TODO: render_stream (partial + flash -> flash.now + optional replace|append + notice|alert) flash.now[:notice] = "coucou ##{COUNT}" render turbo_stream: [ turbo_stream.replace(:flash, partial: 'layouts/components/flash') diff --git a/app/javascript/controllers/flash_controller.js b/app/javascript/controllers/flash_controller.js index 75d8bb6..def2cc8 100644 --- a/app/javascript/controllers/flash_controller.js +++ b/app/javascript/controllers/flash_controller.js @@ -14,7 +14,7 @@ export default class FlashController extends Controller { static targets = ['flashItem'] connect() { - if (FlashController.should_popup) { this.buildPopupFromWithin() } + if (FlashController.should_popup) { this.buildPopupsFromWithin() } } enable() { FlashController.should_popup = true } @@ -27,7 +27,7 @@ export default class FlashController extends Controller { textNotice(message) { return `${this.iconNotice()}
${message}
` } textAlert(message) { return `${this.iconAlert()}
${message}
` } - buildPopupFromWithin() { + buildPopupsFromWithin() { FlashController.should_popup = false this.flashItemTargets.forEach((item) => { this.onPopupEvent({ detail: { type: item.dataset.type, message: item.textContent.trim() } }) diff --git a/app/views/layouts/components/_flash.html.erb b/app/views/layouts/components/_flash.html.erb index e0e424e..c44b0c1 100644 --- a/app/views/layouts/components/_flash.html.erb +++ b/app/views/layouts/components/_flash.html.erb @@ -4,7 +4,7 @@ action: " turbo:before-fetch-request@window->flash#enable turbo:visit@window->flash#disable - turbo:load@window->flash#buildPopupFromWithin + turbo:load@window->flash#buildPopupsFromWithin popup-toast@window->flash#onPopupEvent " } do %>