Skip to content

Commit

Permalink
Move to Turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
miharekar committed Jan 4, 2021
1 parent 6a54feb commit ea5e083
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -10,7 +10,7 @@ gem "pg"
gem "puma"
gem "sass-rails", ">= 6"
gem "webpacker", "~> 4.0"
gem "turbolinks", "~> 5"
gem "turbo-rails"
gem "bootsnap", ">= 1.4.2", require: false

gem "slim"
Expand Down
25 changes: 13 additions & 12 deletions Gemfile.lock
Expand Up @@ -106,13 +106,13 @@ GEM
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.8.5)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.7.0)
launchy (~> 2.2)
listen (3.3.3)
listen (3.4.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.8.0)
Expand All @@ -128,13 +128,14 @@ GEM
mime-types-data (3.2020.1104)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
mini_portile2 (2.5.0)
minitest (5.14.2)
msgpack (1.3.3)
netrc (0.11.0)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
nokogiri (1.11.0)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
orm_adapter (0.5.0)
pagy (3.10.0)
parallel (1.20.1)
Expand All @@ -150,6 +151,7 @@ GEM
public_suffix (4.0.6)
puma (5.1.1)
nio4r (~> 2.0)
racc (1.5.2)
rack (2.2.3)
rack-mini-profiler (2.3.0)
rack (>= 1.2.0)
Expand Down Expand Up @@ -208,16 +210,16 @@ GEM
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.3.0)
rubocop-ast (1.4.0)
parser (>= 2.7.1.5)
rubocop-performance (1.9.1)
rubocop-performance (1.9.2)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.9.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.90.0, < 2.0)
ruby-progressbar (1.10.1)
ruby-progressbar (1.11.0)
rubyzip (2.3.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
Expand Down Expand Up @@ -247,9 +249,8 @@ GEM
thor (1.0.1)
tickly (2.1.7)
tilt (2.0.10)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
turbo-rails (0.5.2)
rails (>= 6.0.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unf (0.1.4)
Expand Down Expand Up @@ -301,7 +302,7 @@ DEPENDENCIES
slim
stackprof
tickly
turbolinks (~> 5)
turbo-rails
web-console (>= 3.3.0)
webpacker (~> 4.0)

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/custom/pagy.js
Expand Up @@ -38,7 +38,7 @@ function loadMore(event) {
loadNextPage(data.page, JSON.parse(data.params))
}

document.addEventListener("turbolinks:load", function (xhr) {
document.addEventListener("turbo:load", function (xhr) {
if (document.getElementById("pagy-load-more")) {
document.getElementById("pagy-load-more").addEventListener("click", loadMore)
}
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/custom/range.js
@@ -1,4 +1,4 @@
document.addEventListener("turbolinks:load", function (xhr) {
document.addEventListener("turbo:load", function (xhr) {
if (document.getElementsByClassName("shot-range").length > 0) {
Array.from(document.getElementsByClassName("shot-range")).forEach((el) => {
dot = el.parentElement.getElementsByClassName("dot")[0]
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/custom/shots.js
Expand Up @@ -167,7 +167,7 @@ function drawChart() {
}
}

document.addEventListener("turbolinks:load", function (xhr) {
document.addEventListener("turbo:load", function (xhr) {
if (document.getElementById("mainChart")) {
if (window.selectedSkin === null || window.selectedSkin === "") {
selectedSkin = "classic"
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/custom/time.js
Expand Up @@ -14,7 +14,7 @@ function setTimezoneCookie() {
document.cookie = "browser.timezone=" + (timezone || "") + "; path=/";
}

document.addEventListener("turbolinks:load", function (xhr) {
document.addEventListener("turbo:load", function (xhr) {
convertTimeToLocal()
setTimezoneCookie()
})
8 changes: 5 additions & 3 deletions app/javascript/custom/upload.js
@@ -1,3 +1,5 @@
import { Turbo, cable } from "@hotwired/turbo-rails"

function fadeAwayFlash() {
setTimeout(function () {
Array.from(document.getElementsByClassName("fade-away")).forEach((el) => {
Expand All @@ -10,7 +12,7 @@ function fadeAwayFlash() {
}, 5000);
}

document.addEventListener("turbolinks:load", function () {
document.addEventListener("turbo:load", function () {
const dropArea = document.getElementById("drop-area");

if (dropArea) {
Expand Down Expand Up @@ -48,12 +50,12 @@ document.addEventListener("turbolinks:load", function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
if (dropArea.dataset.bulk === "true") {
Turbolinks.visit("/shots")
Turbo.visit("/shots")
fadeAwayFlash()
} else {
let queryParams = new URLSearchParams(window.location.search)
let id = JSON.parse(xhr.responseText).id
Turbolinks.visit("/shots/" + id + "?" + queryParams.toString())
Turbo.visit("/shots/" + id + "?" + queryParams.toString())
}
} else {
loader.classList.add("d-none")
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/packs/application.js
Expand Up @@ -3,8 +3,8 @@
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

require("@rails/ujs").start()
require("turbolinks").start()
import { Turbo, cable } from "@hotwired/turbo-rails"

// require("channels")
// require("@rails/activestorage").start()

Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.slim
@@ -1,6 +1,6 @@
= render "shared/flash"
h2.blue Sign In
= form_with(model: resource, as: resource_name, url: session_path(resource_name), class: "pure-form pure-form-stacked") do |f|
= form_with(model: resource, as: resource_name, url: session_path(resource_name), class: "pure-form pure-form-stacked", data: {turbo: false}) do |f|
.field
= f.label :email
= f.email_field :email, autofocus: true, autocomplete: "email"
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.slim
Expand Up @@ -12,8 +12,8 @@ html
link href="/site.webmanifest" rel="manifest"
link color="#000000" href="/safari-pinned-tab.svg" rel="mask-icon"

= stylesheet_link_tag "application", media: "all", "data-turbolinks-track": "reload"
= javascript_pack_tag "application", "data-turbolinks-track": "reload"
= stylesheet_link_tag "application", media: "all", "data-turbo-track": "reload"
= javascript_pack_tag "application", "data-turbo-track": "reload"
body class=('black' if current_user&.skin&.parameterize == "dsx")
.wrapper
.pure-g
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_flash.slim
@@ -1,3 +1,3 @@
- flash.each do |name, msg|
p.center.blue.toggle-content.is-visible.fade-away
p.center.toggle-content.is-visible.fade-away class=(name == "alert" ? "red" : "blue")
= content_tag :strong, msg, id: "flash_#{name}"
2 changes: 1 addition & 1 deletion app/views/shared/_header.html.slim
Expand Up @@ -18,7 +18,7 @@
- else
- if ['passwords', 'sessions', 'registrations'].exclude?(controller_name)
li.pure-menu-item
= form_with(url: user_session_path, model: User, method: :post, class: "pure-form d-none d-sm-block") do |f|
= form_with(url: user_session_path, model: User, method: :post, class: "pure-form d-none d-sm-block", data: {turbo: false}) do |f|
= f.email_field :email, placeholder: "Email", size: 12, autocomplete: "email", class: "right-margin"
= f.password_field :password, placeholder: "Password", size: 12, autocomplete: "current-password", class: "right-margin"
= f.hidden_field :remember_me, value: 1
Expand Down
23 changes: 21 additions & 2 deletions config/initializers/devise.rb
@@ -1,5 +1,24 @@
# frozen_string_literal: true

class TurboController < ApplicationController
class Responder < ActionController::Responder
def to_turbo_stream
controller.render(options.merge(formats: :html))
rescue ActionView::MissingTemplate => e
raise e if get?

if has_errors? && default_action
render rendering_options.merge(formats: :html, status: :unprocessable_entity)
else
redirect_to navigation_location
end
end
end

self.responder = Responder
respond_to :html, :turbo_stream
end

# Assuming you have not yet modified this file, each configuration option below
# is set to its default value. Note that some are commented out while others
# are not: uncommented lines are intended to protect your configuration from
Expand All @@ -18,7 +37,7 @@

# ==> Controller configuration
# Configure the parent class to the devise controllers.
# config.parent_controller = 'DeviseController'
config.parent_controller = "TurboController"

# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
Expand Down Expand Up @@ -263,7 +282,7 @@
# should add them to the navigational formats lists.
#
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ['*/*', :html]
config.navigational_formats = ["*/*", :html, :turbo_stream]

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
Expand Down
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -2,15 +2,14 @@
"name": "decent_visualizer_rails",
"private": true,
"dependencies": {
"@hotwired/turbo-rails": "https://github.com/hotwired/turbo/archive/dev-builds/latest.tar.gz",
"@rails/actioncable": "^6.1",
"@rails/activestorage": "^6.1",
"@rails/ujs": "^6.1",
"@rails/webpacker": "5.2.1",
"chart.js": "^2.9.4",
"chartjs-plugin-annotation": "^0.5.7",
"chartjs-plugin-crosshair": "https://github.com/miharekar/chartjs-plugin-crosshair",
"purecss": "^2.0.3",
"turbolinks": "^5.2.0"
"purecss": "^2.0.3"
},
"version": "0.2.0",
"devDependencies": {
Expand Down
63 changes: 26 additions & 37 deletions yarn.lock
Expand Up @@ -828,6 +828,10 @@
resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"
integrity sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw==

"@hotwired/turbo-rails@https://github.com/hotwired/turbo/archive/dev-builds/latest.tar.gz":
version "7.0.0-beta.1"
resolved "https://github.com/hotwired/turbo/archive/dev-builds/latest.tar.gz#383cdc21c4de93e28751b10189bab9c4d3a68a51"

"@npmcli/move-file@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@npmcli/move-file/-/move-file-1.0.1.tgz#de103070dac0f48ce49cf6693c23af59c0f70464"
Expand All @@ -847,11 +851,6 @@
dependencies:
spark-md5 "^3.0.0"

"@rails/ujs@^6.1":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.1.0.tgz#9a48df6511cb2b472c9f596c1f37dc0af022e751"
integrity sha512-kQNKyM4ePAc4u9eR1c4OqrbAHH+3SJXt++8izIjeaZeg+P7yBtgoF/dogMD/JPPowNC74ACFpM/4op0Ggp/fPw==

"@rails/webpacker@5.2.1":
version "5.2.1"
resolved "https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-5.2.1.tgz#87cdbd4af2090ae2d74bdc51f6f04717d907c5b3"
Expand Down Expand Up @@ -915,9 +914,9 @@
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/node@*":
version "14.14.16"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.16.tgz#3cc351f8d48101deadfed4c9e4f116048d437b4b"
integrity sha512-naXYePhweTi+BMv11TgioE2/FXU4fSl29HAH1ffxVciNsH3rYXjNP2yM8wqmSm7jS20gM8TIklKiTen+1iVncw==
version "14.14.19"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.19.tgz#5135176a8330b88ece4e9ab1fdcfc0a545b4bab4"
integrity sha512-4nhBPStMK04rruRVtVc6cDqhu7S9GZai0fpXgPXrFpcPX6Xul8xnrjSdGB4KPBVYG/R5+fXWdCM8qBoiULWGPQ==

"@types/parse-json@^4.0.0":
version "4.0.0"
Expand Down Expand Up @@ -1585,7 +1584,7 @@ browserify-zlib@^0.2.0:
dependencies:
pako "~1.0.5"

browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.14.5, browserslist@^4.15.0, browserslist@^4.6.4:
browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.14.5, browserslist@^4.16.0, browserslist@^4.6.4:
version "4.16.0"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.16.0.tgz#410277627500be3cb28a1bfe037586fbedf9488b"
integrity sha512-/j6k8R0p3nxOC6kx5JGAxsnhc9ixaWJfYc+TNTzxg6+ARaESAvQGV7h0uNOB4t+pLQJZWzcrMxXOxjgsCj3dqQ==
Expand Down Expand Up @@ -1755,9 +1754,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001165:
version "1.0.30001171"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001171.tgz#3291e11e02699ad0a29e69b8d407666fc843eba7"
integrity sha512-5Alrh8TTYPG9IH4UkRqEBZoEToWRLvPbSQokvzSz0lii8/FOWKG4keO1HoYfPWs8IF/NH/dyNPg1cmJGvV3Zlg==
version "1.0.30001173"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001173.tgz#3c47bbe3cd6d7a9eda7f50ac016d158005569f56"
integrity sha512-R3aqmjrICdGCTAnSXtNyvWYMK3YtV5jwudbq0T7nN9k4kmE4CBuwPqyJ+KBzepSTh0huivV2gLbSMEzTTmfeYw==

case-sensitive-paths-webpack-plugin@^2.3.0:
version "2.3.0"
Expand Down Expand Up @@ -2112,17 +2111,17 @@ copy-descriptor@^0.1.0:
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=

core-js-compat@^3.8.0:
version "3.8.1"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.8.1.tgz#8d1ddd341d660ba6194cbe0ce60f4c794c87a36e"
integrity sha512-a16TLmy9NVD1rkjUGbwuyWkiDoN0FDpAwrfLONvHFQx0D9k7J9y0srwMT8QP/Z6HE3MIFaVynEeYwZwPX1o5RQ==
version "3.8.2"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.8.2.tgz#3717f51f6c3d2ebba8cbf27619b57160029d1d4c"
integrity sha512-LO8uL9lOIyRRrQmZxHZFl1RV+ZbcsAkFWTktn5SmH40WgLtSNYN4m4W2v9ONT147PxBY/XrRhrWq8TlvObyUjQ==
dependencies:
browserslist "^4.15.0"
browserslist "^4.16.0"
semver "7.0.0"

core-js@^3.6.5:
version "3.8.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.8.1.tgz#f51523668ac8a294d1285c3b9db44025fda66d47"
integrity sha512-9Id2xHY1W7m8hCl8NkhQn5CufmF/WuR30BTRewvCXc1aZd3kMECwNZ69ndLbekKfakw9Rf2Xyc+QR6E7Gg+obg==
version "3.8.2"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.8.2.tgz#0a1fd6709246da9ca8eff5bb0cbd15fba9ac7044"
integrity sha512-FfApuSRgrR6G5s58casCBd9M2k+4ikuu4wbW6pJyYU7bd9zvFc9qf7vr5xmrZOhT9nn+8uwlH1oRR9jTnFoA3A==

core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
Expand Down Expand Up @@ -3526,9 +3525,9 @@ http-errors@~1.7.2:
toidentifier "1.0.0"

http-parser-js@>=0.5.1:
version "0.5.2"
resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.2.tgz#da2e31d237b393aae72ace43882dd7e270a8ff77"
integrity sha512-opCO9ASqg5Wy2FNo7A0sxy71yGbbkJJXLdgMK04Tcypw9jr2MgWbyubb0+WdmDmGnFflO7fRbqbaihh/ENDlRQ==
version "0.5.3"
resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.3.tgz#01d2709c79d41698bb01d4decc5e9da4e4a033d9"
integrity sha512-t7hjvef/5HEK7RWTdUzVUhl8zkEu+LlaE0IYzdMuvbSDipxBRpOn4Uhw8ZyECEa808iVT8XCjzo6xmYt4CiLZg==

http-proxy-middleware@0.19.1:
version "0.19.1"
Expand Down Expand Up @@ -4415,22 +4414,17 @@ miller-rabin@^4.0.0:
bn.js "^4.0.0"
brorand "^1.0.1"

mime-db@1.44.0:
version "1.44.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92"
integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==

"mime-db@>= 1.43.0 < 2":
mime-db@1.45.0, "mime-db@>= 1.43.0 < 2":
version "1.45.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.45.0.tgz#cceeda21ccd7c3a745eba2decd55d4b73e7879ea"
integrity sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==

mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.19, mime-types@~2.1.24:
version "2.1.27"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f"
integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==
version "2.1.28"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.28.tgz#1160c4757eab2c5363888e005273ecf79d2a0ecd"
integrity sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==
dependencies:
mime-db "1.44.0"
mime-db "1.45.0"

mime@1.6.0:
version "1.6.0"
Expand Down Expand Up @@ -7172,11 +7166,6 @@ tunnel-agent@^0.6.0:
dependencies:
safe-buffer "^5.0.1"

turbolinks@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/turbolinks/-/turbolinks-5.2.0.tgz#e6877a55ea5c1cb3bb225f0a4ae303d6d32ff77c"
integrity sha512-pMiez3tyBo6uRHFNNZoYMmrES/IaGgMhQQM+VFF36keryjb5ms0XkVpmKHkfW/4Vy96qiGW3K9bz0tF5sK9bBw==

tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
Expand Down

0 comments on commit ea5e083

Please sign in to comment.