From 96cf0b7dd54f60e71df4031308ae33200bb0e1ac Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 8 Jul 2024 20:48:08 +0200 Subject: [PATCH] Fix EditorData cache --- app/Form/Resources/FormResource.php | 1 + app/Lib/Editor/EditorData.php | 17 ++++++++++------- resources/js/views/form/Index.vue | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Form/Resources/FormResource.php b/app/Form/Resources/FormResource.php index 818d36b2..69437e42 100644 --- a/app/Form/Resources/FormResource.php +++ b/app/Form/Resources/FormResource.php @@ -51,6 +51,7 @@ class FormResource extends JsonResource 'has_nami_field' => $this->getFields()->hasNamiField(), 'export' => $this->export, 'needs_prevention' => $this->needs_prevention, + 'prevention_text' => $this->prevention_text, 'links' => [ 'participant_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => null]), 'participant_root_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => -1]), diff --git a/app/Lib/Editor/EditorData.php b/app/Lib/Editor/EditorData.php index 7794eb31..094b3fb7 100644 --- a/app/Lib/Editor/EditorData.php +++ b/app/Lib/Editor/EditorData.php @@ -18,7 +18,7 @@ class EditorData extends Data implements Editorable public function placeholder(string $search, string $replacement): self { $replacedBlocks = str(json_encode($this->blocks))->replace('{' . $search . '}', $replacement); - $this->blocks = json_decode($replacedBlocks); + $this->blocks = json_decode($replacedBlocks, true); return $this; } @@ -42,14 +42,15 @@ class EditorData extends Data implements Editorable public function append(Editorable $editorable): self { - $this->blocks = array_merge($this->blocks, $editorable->toEditorData()->blocks); - - return $this; + return self::from([ + ...$this->toArray(), + 'blocks' => array_merge($this->blocks, $editorable->toEditorData()->blocks), + ]); } public function replaceWithList(string $blockContent, array $replacements): self { - $this->blocks = collect($this->blocks)->map(function ($block) use ($blockContent, $replacements) { + $blocks = collect($this->blocks)->map(function ($block) use ($blockContent, $replacements) { if (data_get($block, 'type') !== 'paragraph') { return $block; } @@ -71,8 +72,10 @@ class EditorData extends Data implements Editorable return $block; })->toArray(); - - return $this; + return self::from([ + ...$this->toArray(), + 'blocks' => $blocks, + ]); } public function toEditorData(): EditorData diff --git a/resources/js/views/form/Index.vue b/resources/js/views/form/Index.vue index 45160c0e..01f147f6 100644 --- a/resources/js/views/form/Index.vue +++ b/resources/js/views/form/Index.vue @@ -43,7 +43,6 @@ -