Browse Source

Refactor comments

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

2
assets/controllers/comments_mercure_controller.js

@ -37,7 +37,7 @@ export default class extends Controller {
const data = JSON.parse(event.data); // { comments, profiles, ... } const data = JSON.parse(event.data); // { comments, profiles, ... }
const live = this._getLiveController(); const live = this._getLiveController();
if (live) { 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 live.render(); // <- asks server to re-render
} }
}; };

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

@ -20,7 +20,7 @@ final class Comments
// Writable prop the browser can set // Writable prop the browser can set
#[LiveProp(writable: true)] #[LiveProp(writable: true)]
public array $payload = []; // { comments, profiles, ... } public string $payload; // { comments, profiles, ... }
// Live input // Live input
#[LiveProp(writable: false)] #[LiveProp(writable: false)]
@ -60,8 +60,9 @@ final class Comments
/** Expose a view model to the template; keeps all parsing server-side */ /** Expose a view model to the template; keeps all parsing server-side */
public function getPayload(): array public function getPayload(): array
{ {
$payload = $this->payload; if (!empty($this->payload)) {
if (!$payload) { $payload = json_decode($this->payload);
} else {
$payload = $this->redisCacheService->getCommentsPayload($this->current) ?? [ $payload = $this->redisCacheService->getCommentsPayload($this->current) ?? [
'comments' => [], 'comments' => [],
'profiles' => [], 'profiles' => [],

Loading…
Cancel
Save