Skip to content

Commit

Permalink
fix: remove js bundeling
Browse files Browse the repository at this point in the history
  • Loading branch information
Waishnav committed Jul 28, 2024
1 parent 187c67f commit 59f4315
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
.log
.sqlite3
/test/dummy/tmp
/node_modules
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ gem "appraisal"
gem "standardrb"
gem "font-awesome-sass", "~> 5.13.1"
gem "sqlite3"

gem "sprockets-rails"
gem "jsbundling-rails", "~> 1.1"
44 changes: 41 additions & 3 deletions app/views/layouts/simple_discussion.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,44 @@

<% parent_layout("application") %>

<% SimpleDiscussion::Engine.javascripts.each do |js_path| %>
<%= javascript_include_tag js_path %>
<% end %>
<script type="module">
import { Application, Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
window.Stimulus = Application.start()

Stimulus.register("dropdown", class extends Controller {
static targets = ["dropdownButton", "dropdownMenu"]

connect() {
this.dropdownButtonTarget.addEventListener("click", this.toggleDropdown.bind(this))
// if click somewhere else in the document, close the dropdown
window.addEventListener("click", (event) => {
if (!this.dropdownButtonTarget.contains(event.target)) {
this.dropdownMenuTarget.classList.remove("show")
}
})
}

// note that we are using bootstrap
toggleDropdown() {
this.dropdownMenuTarget.classList.toggle("show")
}
})


Stimulus.register("report-spam", class extends Controller {
static targets = ["reportSpamButton"]

connect() {
const reportSpamForm = document.getElementById("reportSpamForm")
const postId = this.element.dataset.postId
this.reportSpamButtonTarget.addEventListener("click", () => {
const formActionArray = reportSpamForm.action.split("/")
if (formActionArray[formActionArray.length - 2] === "threads") {
reportSpamForm.action += `/posts/${postId}/report_spam`
} else {
reportSpamForm.action = reportSpamForm.action.replace(/\/\d+\//, `/${postId}/`)
}
})
}
})
</script>
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ en:
login: "Log in"
commented: "commented:"
inappropriate_language_error_message: "contains inappropriate language: %{words}"
unmark_as_solution: "Démarquer comme solution"
mark_as_solution: "Marquer comme solution"
unmark_as_solution: "Unmark as Solution"
mark_as_solution: "Mark as Solution"
report_post: "Report Post"
19 changes: 0 additions & 19 deletions lib/simple_discussion/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,5 @@ class Engine < ::Rails::Engine
config.after_initialize do
SimpleDiscussion::Engine.routes.default_url_options = ActionMailer::Base.default_url_options
end

# javascripts assets precompiled for dropdown and markdown text editor
@@javascripts = []

initializer "simple_discussion.assets.precompile" do |app|
app.config.assets.precompile += [
"simple_discussion/application.js"
]
end

def self.add_javascript(script)
@@javascripts << script
end

def self.javascripts
@@javascripts
end

add_javascript "simple_discussion/application.js"
end
end
15 changes: 0 additions & 15 deletions package.json

This file was deleted.

0 comments on commit 59f4315

Please sign in to comment.