From a6f6ffa624f46467770af37e14a59c929404bd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Sun, 26 Oct 2025 18:21:35 +0100 Subject: [PATCH] Refactor comments --- assets/controllers/comments_mercure_controller.js | 2 +- src/Twig/Components/Organisms/Comments.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/controllers/comments_mercure_controller.js b/assets/controllers/comments_mercure_controller.js index 715d102..4584944 100644 --- a/assets/controllers/comments_mercure_controller.js +++ b/assets/controllers/comments_mercure_controller.js @@ -37,7 +37,7 @@ export default class extends Controller { const data = JSON.parse(event.data); // { comments, profiles, ... } const live = this._getLiveController(); if (live) { - live.set('payload', data); // <- updates the writable LiveProp + live.set('payload', JSON.stringify(data)); // <- updates the writable LiveProp live.render(); // <- asks server to re-render } }; diff --git a/src/Twig/Components/Organisms/Comments.php b/src/Twig/Components/Organisms/Comments.php index 087cdb2..ce58c89 100644 --- a/src/Twig/Components/Organisms/Comments.php +++ b/src/Twig/Components/Organisms/Comments.php @@ -20,7 +20,7 @@ final class Comments // Writable prop the browser can set #[LiveProp(writable: true)] - public array $payload = []; // { comments, profiles, ... } + public string $payload; // { comments, profiles, ... } // Live input #[LiveProp(writable: false)] @@ -60,8 +60,9 @@ final class Comments /** Expose a view model to the template; keeps all parsing server-side */ public function getPayload(): array { - $payload = $this->payload; - if (!$payload) { + if (!empty($this->payload)) { + $payload = json_decode($this->payload); + } else { $payload = $this->redisCacheService->getCommentsPayload($this->current) ?? [ 'comments' => [], 'profiles' => [],