Browse Source

Refactor comments

imwald
Nuša Pukšič 3 months ago
parent
commit
42f14305f4
  1. 6
      assets/controllers/comments_mercure_controller.js
  2. 2
      templates/components/Organisms/Comments.html.twig

6
assets/controllers/comments_mercure_controller.js

@ -14,12 +14,13 @@ import { Controller } from "@hotwired/stimulus"; @@ -14,12 +14,13 @@ import { Controller } from "@hotwired/stimulus";
*/
export default class extends Controller {
static values = {
coordinate: String, // e.g. "nevent1..." or your coordinate id
coordinate: String,
};
static targets = ["list", "loading"];
connect() {
console.log("[comments-mercure] Connecting to Mercure for comments at", this.coordinateValue);
this._debounceId = null;
this._opened = false;
@ -54,7 +55,8 @@ export default class extends Controller { @@ -54,7 +55,8 @@ export default class extends Controller {
// Keep the UI usable even if Mercure hiccups
this._hideLoading();
};
this.eventSource.onmessage = () => {
this.eventSource.onmessage = (e) => {
console.log('Mercure MSG', e.data);
// We ignore the payload; Mercure is just a signal to re-render the live component
this._debouncedRefresh();
};

2
templates/components/Organisms/Comments.html.twig

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<div
{{ attributes }}
class="comments"
data-controller="comments-mercure"
data-controller="comments_mercure"
data-comments-mercure-coordinate-value="{{ current }}"
data-comments-mercure-target="root"
id="comments-{{ current|e('html_attr') }}"

Loading…
Cancel
Save