Skip to content

Commit c7d8bae

Browse files
authored
Filament Features: Table Action, Header Action, Widget and Infolist Entry (#22)
- Added a Table Action to render comments - Added a Page/Header action to render comments - Added an Infolist Entry to render comments - Added a Widget to render comments e.g as a footerWidget for a page
2 parents 8d13ef6 + 7731d79 commit c7d8bae

File tree

13 files changed

+132
-4
lines changed

13 files changed

+132
-4
lines changed

resources/dist/nested-comments.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@if(isset($record))
2+
<livewire:nested-comments::comments :record="$record" />
3+
@else
4+
<p>No Commentable record set.</p>
5+
@endif

resources/views/components/emoji-selector.blade.php

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
2+
<livewire:nested-comments::comments :record="$getRecord()" />
3+
</x-dynamic-component>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<x-filament-widgets::widget>
2+
@if($this->record)
3+
<livewire:nested-comments::comments :record="$this->record" />
4+
@else
5+
<x-filament::section>
6+
No Commentable record found. Please pass a record to the widget.
7+
</x-filament::section>
8+
@endif
9+
</x-filament-widgets::widget>

resources/views/livewire/comments.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<x-filament::section wire:poll.keep-alive class="!ring-0">
1+
<x-filament::section wire:poll.10s :compact="true" class="!ring-0 !shadow-none !p-0">
22
<x-slot name="heading">
33
<div class="flex items-center space-x-2">
44
<div>

src/Concerns/HasComments.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public function comments(): MorphMany
2121

2222
public function getCommentsCountAttribute(): int
2323
{
24-
return $this->comments()->count();
24+
return $this->comments()
25+
->where('parent_id', '=', null)
26+
->count();
2527
}
2628

2729
public function getCommentsTree($offset = null, $limit = null, $columns = ['*']): Collection
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Coolsam\NestedComments\Filament\Actions;
4+
5+
use Coolsam\NestedComments\NestedComments;
6+
use Filament\Actions\Action;
7+
use Illuminate\Contracts\Support\Htmlable;
8+
use Illuminate\Contracts\View\View;
9+
10+
class CommentsAction extends Action
11+
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
$this->modalWidth('4xl')
16+
->slideOver()
17+
->modalHeading(fn (): string => __('View Comments'));
18+
$this->modalSubmitAction(false);
19+
$this->modalCancelActionLabel(__('Close'));
20+
$this->icon('heroicon-o-chat-bubble-left-right');
21+
$this->modalIcon('heroicon-o-chat-bubble-left-right');
22+
}
23+
24+
public static function getDefaultName(): ?string
25+
{
26+
return 'comments';
27+
}
28+
29+
public function getModalContent(): View | Htmlable | null
30+
{
31+
$record = $this->getRecord();
32+
33+
return app(NestedComments::class)->renderCommentsComponent($record);
34+
}
35+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Coolsam\NestedComments\Filament\Infolists;
4+
5+
use Closure;
6+
use Filament\Infolists\Components\Entry;
7+
8+
class CommentsEntry extends Entry
9+
{
10+
protected bool | Closure $isLabelHidden = true;
11+
12+
protected string $view = 'nested-comments::filament.infolists.comments-entry';
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Coolsam\NestedComments\Filament\Tables\Actions;
4+
5+
use Coolsam\NestedComments\NestedComments;
6+
use Filament\Tables\Actions\Action;
7+
use Illuminate\Contracts\Support\Htmlable;
8+
use Illuminate\Contracts\View\View;
9+
10+
class CommentsAction extends Action
11+
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
$this->modalWidth('4xl')
16+
->slideOver()
17+
->modalHeading(fn (): string => __('Comments'));
18+
$this->modalSubmitAction(false);
19+
$this->modalCancelActionLabel(__('Close'));
20+
$this->icon('heroicon-o-chat-bubble-left-right');
21+
$this->modalIcon('heroicon-o-chat-bubble-left-right');
22+
}
23+
24+
public static function getDefaultName(): ?string
25+
{
26+
return 'comments';
27+
}
28+
29+
public function getModalContent(): View | Htmlable | null
30+
{
31+
$record = $this->getRecord();
32+
33+
return app(NestedComments::class)->renderCommentsComponent($record);
34+
}
35+
}

0 commit comments

Comments
 (0)