Browse Source

Refactor comments, fix template

imwald
Nuša Pukšič 3 months ago
parent
commit
c3093dda6b
  1. 4
      assets/controllers/comments_mercure_controller.js
  2. 2
      src/Twig/Components/Organisms/Comments.php

4
assets/controllers/comments_mercure_controller.js

@ -27,8 +27,8 @@ export default class extends Controller { @@ -27,8 +27,8 @@ export default class extends Controller {
this.es = new EventSource(url.toString());
this.es.onmessage = async (msg) => {
this._showLoading();
this.component.set('payloadJson', JSON.stringify(msg.data));
await this.component.render(); // Live re-hydrates from your server/cache
this.component.set('payloadJson', msg.data);
await this.component.render();
};
}

2
src/Twig/Components/Organisms/Comments.php

@ -60,7 +60,7 @@ final class Comments @@ -60,7 +60,7 @@ final class Comments
/** Expose a view model to the template; keeps all parsing server-side */
public function getPayload(): array
{
$data = $this->payloadJson !== ''
$data = !empty($this->payloadJson)
? (json_decode($this->payloadJson, true) ?: [])
: $this->redisCacheService->getCommentsPayload($this->current) ?? [
'comments' => [],

Loading…
Cancel
Save