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 resources/dist/nested-comments.css

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions resources/views/components/comments.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@if(isset($record))
<livewire:nested-comments::comments :record="$record" />
@else
<p>No Commentable record set.</p>
@endif
1 change: 0 additions & 1 deletion resources/views/components/emoji-selector.blade.php

This file was deleted.

3 changes: 3 additions & 0 deletions resources/views/filament/infolists/comments-entry.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
<livewire:nested-comments::comments :record="$getRecord()" />
</x-dynamic-component>
9 changes: 9 additions & 0 deletions resources/views/filament/widgets/comments-widget.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<x-filament-widgets::widget>
@if($this->record)
<livewire:nested-comments::comments :record="$this->record" />
@else
<x-filament::section>
No Commentable record found. Please pass a record to the widget.
</x-filament::section>
@endif
</x-filament-widgets::widget>
2 changes: 1 addition & 1 deletion resources/views/livewire/comments.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<x-filament::section wire:poll.keep-alive class="!ring-0">
<x-filament::section wire:poll.10s :compact="true" class="!ring-0 !shadow-none !p-0">
<x-slot name="heading">
<div class="flex items-center space-x-2">
<div>
Expand Down
4 changes: 3 additions & 1 deletion src/Concerns/HasComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function comments(): MorphMany

public function getCommentsCountAttribute(): int
{
return $this->comments()->count();
return $this->comments()
->where('parent_id', '=', null)
->count();
}

public function getCommentsTree($offset = null, $limit = null, $columns = ['*']): Collection
Expand Down
35 changes: 35 additions & 0 deletions src/Filament/Actions/CommentsAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Coolsam\NestedComments\Filament\Actions;

use Coolsam\NestedComments\NestedComments;
use Filament\Actions\Action;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;

class CommentsAction extends Action
{
protected function setUp(): void
{
parent::setUp();
$this->modalWidth('4xl')
->slideOver()
->modalHeading(fn (): string => __('View Comments'));
$this->modalSubmitAction(false);
$this->modalCancelActionLabel(__('Close'));
$this->icon('heroicon-o-chat-bubble-left-right');
$this->modalIcon('heroicon-o-chat-bubble-left-right');
}

public static function getDefaultName(): ?string
{
return 'comments';
}

public function getModalContent(): View | Htmlable | null
{
$record = $this->getRecord();

return app(NestedComments::class)->renderCommentsComponent($record);
}
}
13 changes: 13 additions & 0 deletions src/Filament/Infolists/CommentsEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Coolsam\NestedComments\Filament\Infolists;

use Closure;
use Filament\Infolists\Components\Entry;

class CommentsEntry extends Entry
{
protected bool | Closure $isLabelHidden = true;

protected string $view = 'nested-comments::filament.infolists.comments-entry';

Check failure on line 12 in src/Filament/Infolists/CommentsEntry.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Coolsam\NestedComments\Filament\Infolists\CommentsEntry::$view (view-string) does not accept default value of type string.
}
35 changes: 35 additions & 0 deletions src/Filament/Tables/Actions/CommentsAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Coolsam\NestedComments\Filament\Tables\Actions;

use Coolsam\NestedComments\NestedComments;
use Filament\Tables\Actions\Action;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;

class CommentsAction extends Action
{
protected function setUp(): void
{
parent::setUp();
$this->modalWidth('4xl')
->slideOver()
->modalHeading(fn (): string => __('Comments'));
$this->modalSubmitAction(false);
$this->modalCancelActionLabel(__('Close'));
$this->icon('heroicon-o-chat-bubble-left-right');
$this->modalIcon('heroicon-o-chat-bubble-left-right');
}

public static function getDefaultName(): ?string
{
return 'comments';
}

public function getModalContent(): View | Htmlable | null
{
$record = $this->getRecord();

return app(NestedComments::class)->renderCommentsComponent($record);
}
}
15 changes: 15 additions & 0 deletions src/Filament/Widgets/CommentsWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Coolsam\NestedComments\Filament\Widgets;

use Filament\Widgets\Widget;
use Illuminate\Database\Eloquent\Model;

class CommentsWidget extends Widget
{
public ?Model $record = null;

protected static string $view = 'nested-comments::filament.widgets.comments-widget';

Check failure on line 12 in src/Filament/Widgets/CommentsWidget.php

View workflow job for this annotation

GitHub Actions / phpstan

Static property Coolsam\NestedComments\Filament\Widgets\CommentsWidget::$view (view-string) does not accept default value of type string.

protected int | string | array $columnSpan = 'full';
}
10 changes: 10 additions & 0 deletions src/NestedComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Filament\Support\Facades\FilamentColor;
use FilamentTiptapEditor\Data\MentionItem;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\View\Factory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Illuminate\View\View;
use Spatie\Color\Rgb;

class NestedComments
Expand Down Expand Up @@ -125,4 +128,11 @@ public function getCurrentThreadUsers(string $searchQuery, $commentable): mixed
);
})->toArray();
}

public function renderCommentsComponent(Model $record): \Illuminate\Contracts\View\View | Application | Factory | View
{
return view('nested-comments::components.comments', [
'record' => $record,
]);
}
}
2 changes: 2 additions & 0 deletions src/NestedCommentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Coolsam\NestedComments;

use Coolsam\NestedComments\Commands\NestedCommentsCommand;
use Coolsam\NestedComments\Filament\Widgets\CommentsWidget;
use Coolsam\NestedComments\Http\Middleware\GuestCommentatorMiddleware;
use Coolsam\NestedComments\Livewire\AddComment;
use Coolsam\NestedComments\Livewire\CommentCard;
Expand Down Expand Up @@ -225,6 +226,7 @@ protected function getLivewireComponents(): array
'comment-card' => CommentCard::class,
'add-comment' => AddComment::class,
'reaction-panel' => ReactionPanel::class,
'filament.widgets.comments-widget' => CommentsWidget::class,
];
}
}
Loading