Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Livewire/Comments/CommentComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
30 changes: 10 additions & 20 deletions app/Livewire/Comments/CommentFormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,35 @@ 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 = '';
public ?ModerationTypeEnum $moderationType = null;
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]
Expand Down Expand Up @@ -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,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
@if ($isReplying === true)
<livewire:comments.comment-form-component
wire:key="reply-to-comment-{{ $commentId }}"
:comment="$comment"
:post-id="$comment->post_id"
:parent-id="$commentId"
is-replying="true"
@comment-updated="closeForm()"
@comment-stored="closeForm()"
Expand Down