Make comments cache-safe
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
|
||||
import "@hotwired/turbo-rails"
|
||||
import "extensions"
|
||||
import "initializers"
|
||||
import "controllers"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static classes = [ "myComment" ]
|
||||
|
||||
connect() {
|
||||
this.#myComments.forEach(comment => comment.classList.add(this.myCommentClass))
|
||||
}
|
||||
|
||||
get #myComments() {
|
||||
return this.element.querySelectorAll(`.comment[data-creator-id='${Current.user.id}']`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class Current {
|
||||
get user() {
|
||||
const currentUserId = this.#extractContentFromMetaTag("current-user-id")
|
||||
|
||||
if (currentUserId) {
|
||||
return { id: parseInt(currentUserId) }
|
||||
}
|
||||
}
|
||||
|
||||
#extractContentFromMetaTag(name) {
|
||||
return document.head.querySelector(`meta[name="${name}"]`)?.getAttribute("content")
|
||||
}
|
||||
}
|
||||
|
||||
window.Current = new Current()
|
||||
@@ -0,0 +1 @@
|
||||
import "initializers/current"
|
||||
Reference in New Issue
Block a user