diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 338a0e8..d39ca55 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,3 +1,5 @@ //= link_tree ../images //= link_directory ../stylesheets .css //= link_tree ../builds +//= link_tree ../../javascript .js +//= link_tree ../../../vendor/javascript .js diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..c275ea8 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1,2 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "controllers" diff --git a/app/javascript/controllers/application.js b/app/javascript/controllers/application.js new file mode 100644 index 0000000..1213e85 --- /dev/null +++ b/app/javascript/controllers/application.js @@ -0,0 +1,9 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// Configure Stimulus development experience +application.debug = false +window.Stimulus = application + +export { application } diff --git a/app/javascript/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js new file mode 100644 index 0000000..5975c07 --- /dev/null +++ b/app/javascript/controllers/hello_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.textContent = "Hello World!" + } +} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js new file mode 100644 index 0000000..1156bf8 --- /dev/null +++ b/app/javascript/controllers/index.js @@ -0,0 +1,4 @@ +// Import and register all your controllers from the importmap via controllers/**/*_controller +import { application } from "controllers/application" +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) diff --git a/app/javascript/controllers/thread_controller.js b/app/javascript/controllers/thread_controller.js new file mode 100644 index 0000000..6ace0af --- /dev/null +++ b/app/javascript/controllers/thread_controller.js @@ -0,0 +1,24 @@ +import { Controller } from "@hotwired/stimulus" + +// Connects to data-controller="thread" +export default class extends Controller { + static targets = ["children", "icon"] + + connect() { + // Initially hide children + if (this.hasChildrenTarget) { + this.childrenTarget.classList.add("hidden") + } + } + + toggle() { + if (this.hasChildrenTarget) { + this.childrenTarget.classList.toggle("hidden") + + // Rotate the icon + if (this.hasIconTarget) { + this.iconTarget.classList.toggle("rotate-90") + } + } + } +} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 49f3eca..900d72b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -22,6 +22,7 @@ <%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %> <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> diff --git a/app/views/messages/_thread.html.erb b/app/views/messages/_thread.html.erb index e90e758..40d891d 100644 --- a/app/views/messages/_thread.html.erb +++ b/app/views/messages/_thread.html.erb @@ -1,12 +1,17 @@ -
+
data-controller="thread"<% end %>> <% if depth == 0 %>
-
+
data-action="click->thread#toggle"<% end %>>

+ <% if message.children&.any? %> + + + + <% end %> [#<%= message.list_seq %>] - <%= link_to without_list_prefix(message.subject), "/#{list.name}/#{message.list_seq}" %> + <%= link_to without_list_prefix(message.subject), "/#{list.name}/#{message.list_seq}", data: {action: 'click->thread#toggle:stop'} %> — <%= message.from %>

@@ -38,7 +43,7 @@ <% end %> <% if message.children&.any? %> -
+
data-thread-target="children"<% end %>> <%= render partial: 'thread', collection: message.children, as: :message, locals: {list: list, depth: depth + 1} %>
<% end %> diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 0000000..36502ab --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 0000000..cded577 --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,6 @@ +# Pin npm packages by running ./bin/importmap + +pin "application" +pin "@hotwired/stimulus", to: "stimulus.min.js" +pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" +pin_all_from "app/javascript/controllers", under: "controllers" diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..d32d684 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1 @@ +Rails.backtrace_cleaner.remove_silencers! diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 0000000..e69de29