Browse Source

notyf refactored

pagy
pvincent 10 months ago
parent
commit
0ad4442bad
  1. 12
      app/javascript/application.js
  2. 9
      app/views/layouts/_notification.html.erb

12
app/javascript/application.js

@ -1,16 +1,10 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails" import "@hotwired/turbo-rails"
import "controllers" import "controllers"
import { Notyf } from 'notyf'
window.buildNotyf = ()=>{
const notyf=new Notyf({
duration: 5000,
position: { x: 'center', y: 'top' },
})
return notyf
}
// Notyf
import { Notyf } from 'notyf'
window.Notyf=Notyf
// Customize Turbo default behaviour // Customize Turbo default behaviour
Turbo.setProgressBarDelay(300) Turbo.setProgressBarDelay(300)
// Turbo.session.drive = false

9
app/views/layouts/_notification.html.erb

@ -1,13 +1,14 @@
<h2>NOTIFICATION BAR</h2>
<% if flash.count.positive? %>
<script data-turbo-temporary> <script data-turbo-temporary>
document.addEventListener('turbo:load',(e)=>{ document.addEventListener('turbo:load',(e)=>{
const notyf=window.buildNotyf()
notyf.success('rails notice')
notyf.error('rails alert')
const notyf=new Notyf({ duration: 5000, position: { x: 'center', y: 'top' } })
<% if flash.notice%> notyf.success('<%=flash.notice%>') <%end%>
<% if flash.alert%> notyf.error('<%=flash.alert%>') <%end%>
// useful to prevent flickering from turbo preview // useful to prevent flickering from turbo preview
Turbo.cache.exemptPageFromPreview() Turbo.cache.exemptPageFromPreview()
}, {once: true}) }, {once: true})
</script> </script>
<%end%>
Loading…
Cancel
Save