diff --git a/app/Livewire/Comments/CommentComponent.php b/app/Livewire/Comments/CommentComponent.php index af42b814..9c60b9f3 100644 --- a/app/Livewire/Comments/CommentComponent.php +++ b/app/Livewire/Comments/CommentComponent.php @@ -41,7 +41,7 @@ public function render(): View { $moderationType = $this->appearanceComment?->moderation_type ?? null; - $hasModeratorActions = $this->filterModeratorActions($this->childComments, $this->state === CommentStateEnum::Moderating)->isNotEmpty(); + $hasModeratorActions = !empty($this->childComments) && $this->filterModeratorActions($this->childComments, $this->state === CommentStateEnum::Moderating)->isNotEmpty(); // If there are no decorations to apply, just render the basic comment component. return view('livewire.comments.comment-component', [ diff --git a/app/Livewire/Comments/CommentFormComponent.php b/app/Livewire/Comments/CommentFormComponent.php index acf18230..b9c2c9fb 100644 --- a/app/Livewire/Comments/CommentFormComponent.php +++ b/app/Livewire/Comments/CommentFormComponent.php @@ -21,16 +21,16 @@ final class CommentFormComponent extends Component // Props #[Locked] - public int $postId; + public int $postId = 0; #[Locked] - public ?int $commentId; + public ?int $commentId = null; #[Locked] - public ?int $parentId; + public ?int $parentId = null; #[Locked] - public string $idSuffix; + public string $idSuffix = ''; // Form data public string $body = ''; @@ -38,24 +38,18 @@ final class CommentFormComponent extends Component public string $message = ''; // State - public bool $isEditing; - public bool $isReplying; - public bool $isModerating; + public bool $isEditing = false; + public bool $isReplying = false; + public bool $isModerating = false; // Data not persisted in the client-side snapshot protected ?Comment $comment; - #[Computed] - public function isAdding(): bool - { - return !$this->isEditing && !$this->isReplying && !$this->isModerating; - } - #[Computed] public function isBodyEditable(): bool { - return $this->isAdding || $this->isEditing || - ($this->isModerating && $this->moderationType === ModerationTypeEnum::Edit); + // The body is editable if not moderating, or if the moderator is editing the original comment. + return !$this->isModerating || $this->moderationType === ModerationTypeEnum::Edit; } #[Computed] @@ -103,15 +97,11 @@ public function mount( public function render(): View { - $isAdding = !$this->isEditing && !$this->isReplying && !$this->isModerating; - $isBodyEditable = $isAdding || $this->isEditing || - ($this->isModerating && $this->moderationType === ModerationTypeEnum::Edit); $data = [ 'bodyLabel' => trans('Comment'), 'messageLabel' => trans('Moderation message'), 'buttonText' => trans('Add Comment'), - 'isAdding' => $isAdding, - 'isBodyEditable' => $isBodyEditable, + 'isBodyEditable' => $this->isBodyEditable, 'bodyEditorId' => $this->bodyEditorId, 'messageEditorId' => $this->messageEditorId, ]; diff --git a/resources/views/livewire/comments/comment-component.blade.php b/resources/views/livewire/comments/comment-component.blade.php index e3fe1fa4..05d3f3a0 100644 --- a/resources/views/livewire/comments/comment-component.blade.php +++ b/resources/views/livewire/comments/comment-component.blade.php @@ -92,7 +92,8 @@ @if ($isReplying === true)