Browse Source

refactored3

main
pvincent 18 hours ago
parent
commit
581aa76b49
  1. 6
      app/controllers/notification_controller.rb
  2. 4
      app/javascript/controllers/flash_controller.js
  3. 2
      app/views/layouts/components/_flash.html.erb

6
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')

4
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()}<div>${message}</div>` }
textAlert(message) { return `${this.iconAlert()}<div>${message}</div>` }
buildPopupFromWithin() {
buildPopupsFromWithin() {
FlashController.should_popup = false
this.flashItemTargets.forEach((item) => {
this.onPopupEvent({ detail: { type: item.dataset.type, message: item.textContent.trim() } })

2
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 %>
<div class='hidden'>

Loading…
Cancel
Save