From 0586f88d985d66be77bf2edc584ded0d4339a8f2 Mon Sep 17 00:00:00 2001 From: yamat47 Date: Sat, 17 Aug 2024 13:11:46 +0900 Subject: [PATCH 1/4] Use turbo on media. --- app/app/javascript/application.js | 1 + app/app/views/layouts/media/application.html.haml | 1 + app/config/importmap.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/app/javascript/application.js b/app/app/javascript/application.js index c275ea8..e239947 100644 --- a/app/app/javascript/application.js +++ b/app/app/javascript/application.js @@ -1,2 +1,3 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "controllers" +import "@hotwired/turbo-rails" diff --git a/app/app/views/layouts/media/application.html.haml b/app/app/views/layouts/media/application.html.haml index d17e492..3a3664e 100644 --- a/app/app/views/layouts/media/application.html.haml +++ b/app/app/views/layouts/media/application.html.haml @@ -8,6 +8,7 @@ = csp_meta_tag %link{ rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/yakuhanjp@4.0.1/dist/css/yakuhanjp.css' } = stylesheet_link_tag 'media', 'data-turbo-track': 'reload' + = javascript_importmap_tags %body .application .application__header diff --git a/app/config/importmap.rb b/app/config/importmap.rb index 9cbf71f..98698b8 100644 --- a/app/config/importmap.rb +++ b/app/config/importmap.rb @@ -6,3 +6,4 @@ pin '@hotwired/stimulus', to: 'stimulus.min.js', preload: true pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js', preload: true pin_all_from 'app/javascript/controllers', under: 'controllers' +pin '@hotwired/turbo-rails', to: 'turbo.min.js' From 255db2d19e11e7704edd2af38e64cd1372f04e31 Mon Sep 17 00:00:00 2001 From: yamat47 Date: Sat, 17 Aug 2024 13:17:34 +0900 Subject: [PATCH 2/4] Use hover-click preload acceleration. refs: https://github.com/hotwired/turbo/pull/1101 --- app/app/views/layouts/admin/application.html.haml | 1 + app/app/views/layouts/media/application.html.haml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/app/views/layouts/admin/application.html.haml b/app/app/views/layouts/admin/application.html.haml index 27535ab..b174b29 100644 --- a/app/app/views/layouts/admin/application.html.haml +++ b/app/app/views/layouts/admin/application.html.haml @@ -9,6 +9,7 @@ = csp_meta_tag = stylesheet_link_tag 'admin', 'data-turbo-track': 'reload' = javascript_importmap_tags + %meta{ name: 'turbo-prefetch', content: 'true' } %body - if logged_in? .application diff --git a/app/app/views/layouts/media/application.html.haml b/app/app/views/layouts/media/application.html.haml index 3a3664e..429983a 100644 --- a/app/app/views/layouts/media/application.html.haml +++ b/app/app/views/layouts/media/application.html.haml @@ -9,6 +9,7 @@ %link{ rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/yakuhanjp@4.0.1/dist/css/yakuhanjp.css' } = stylesheet_link_tag 'media', 'data-turbo-track': 'reload' = javascript_importmap_tags + %meta{ name: 'turbo-prefetch', content: 'true' } %body .application .application__header From e44b49f629cd7c6077639f3c33d1be05a8e39af8 Mon Sep 17 00:00:00 2001 From: yamat47 Date: Sat, 17 Aug 2024 13:33:30 +0900 Subject: [PATCH 3/4] Use View Transition. --- app/app/views/layouts/admin/application.html.haml | 1 + app/app/views/layouts/media/application.html.haml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/app/views/layouts/admin/application.html.haml b/app/app/views/layouts/admin/application.html.haml index b174b29..c134a40 100644 --- a/app/app/views/layouts/admin/application.html.haml +++ b/app/app/views/layouts/admin/application.html.haml @@ -10,6 +10,7 @@ = stylesheet_link_tag 'admin', 'data-turbo-track': 'reload' = javascript_importmap_tags %meta{ name: 'turbo-prefetch', content: 'true' } + %meta{ name: 'view-transition', content: 'same-origin' } %body - if logged_in? .application diff --git a/app/app/views/layouts/media/application.html.haml b/app/app/views/layouts/media/application.html.haml index 429983a..2708ebb 100644 --- a/app/app/views/layouts/media/application.html.haml +++ b/app/app/views/layouts/media/application.html.haml @@ -10,6 +10,7 @@ = stylesheet_link_tag 'media', 'data-turbo-track': 'reload' = javascript_importmap_tags %meta{ name: 'turbo-prefetch', content: 'true' } + %meta{ name: 'view-transition', content: 'same-origin' } %body .application .application__header From 5d5adefb8eb6d6845640737c918ed59e6aa89c11 Mon Sep 17 00:00:00 2001 From: yamat47 Date: Sat, 17 Aug 2024 13:36:23 +0900 Subject: [PATCH 4/4] Use turbo page moving in admin list. --- app/app/javascript/controllers/admin_list_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/javascript/controllers/admin_list_controller.js b/app/app/javascript/controllers/admin_list_controller.js index 7eed176..358e064 100644 --- a/app/app/javascript/controllers/admin_list_controller.js +++ b/app/app/javascript/controllers/admin_list_controller.js @@ -6,6 +6,6 @@ export default class extends Controller { const href = event.currentTarget.dataset.href - window.location.href = href + Turbo.visit(href) } }