Skip to content

Commit 22e33f9

Browse files
committed
Add support for Filament 4
1 parent 40e1f1a commit 22e33f9

File tree

11 files changed

+62
-26
lines changed

11 files changed

+62
-26
lines changed

README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ use Kirschbaum\Commentions\Filament\Actions\CommentsTableAction;
8484
])
8585
```
8686

87+
If you are using Filament 4.0, you should use `CommentsAction` in `recordActions` instead:
88+
89+
```php
90+
use Kirschbaum\Commentions\Filament\Actions\CommentsAction;
91+
92+
->recordActions([
93+
CommentsAction::make()
94+
->mentionables(User::all())
95+
])
96+
````
97+
8798
3. Or as a header action:
8899

89100
```php
@@ -99,7 +110,15 @@ protected function getHeaderActions(): array
99110

100111
***
101112

102-
### Configuring the User model and the mentionables
113+
### Configuration
114+
115+
You can publish the configuration file to make changes.
116+
117+
```bash
118+
php artisan vendor:publish --tag="commentions-config"
119+
```
120+
121+
#### Configuring the User model and the mentionables
103122

104123
If your `User` model lives in a different namespace than `App\Models\User`, you can configure it in `config/commentions.php`:
105124

@@ -109,7 +128,7 @@ If your `User` model lives in a different namespace than `App\Models\User`, you
109128
],
110129
```
111130

112-
### Configuring the Comment model
131+
#### Configuring the Comment model
113132

114133
If you need to customize the Comment model, you can extend the `\Kirschbaum\Commentions\Comment` class and then update the `comment.model` option in your `config/commentions.php` file:
115134

@@ -120,20 +139,20 @@ If you need to customize the Comment model, you can extend the `\Kirschbaum\Comm
120139
],
121140
```
122141

123-
### Configuring Comment permissions
142+
#### Configuring Comment permissions
124143

125144
By default, users can create comments, as well as edit and delete their own comments. You can adjust these permissions by implementing your own policy:
126145

127-
#### 1) Create a custom policy
146+
##### 1) Create a custom policy
128147

129148
```php
130149
namespace App\Policies;
131150

132151
use Kirschbaum\Commentions\Comment;
133152
use Kirschbaum\Commentions\Contracts\Commenter;
134-
use Kirschbaum\Commentions\Policies\CommentPolicy;
153+
use Kirschbaum\Commentions\Policies\CommentPolicy as CommentionsPolicy;
135154

136-
class CommentPolicy extends CommentPolicy
155+
class CommentPolicy extends CommentionsPolicy
137156
{
138157
public function create(Commenter $user): bool
139158
{
@@ -152,7 +171,7 @@ class CommentPolicy extends CommentPolicy
152171
}
153172
```
154173

155-
#### 2) Register your policy in the configuration file
174+
##### 2) Register your policy in the configuration file
156175

157176
Update the `comment.policy` option in your `config/commentions.php` file:
158177

@@ -266,13 +285,13 @@ $comment->getMentioned()->each(function (Commenter $commenter) {
266285

267286
### Polling for new comments
268287

269-
Commentions supports polling for new comments. You can enable it on any component by calling the `pollingInterval` method and passing the number of seconds.
288+
Commentions supports polling for new comments. You can enable it on any component by calling the `poll` method and passing the desired interval.
270289

271290
```php
272291
Infolists\Components\Section::make('Comments')
273292
->schema([
274293
CommentsEntry::make('comments')
275-
->pollingInterval(10)
294+
->poll('10s')
276295
]),
277296
```
278297

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"illuminate/support": "^11.0|^12.0",
2727
"illuminate/database": "^11.0|^12.0",
2828
"livewire/livewire": "^3.5",
29-
"filament/support": "^3.2",
30-
"filament/notifications": "^3.2",
31-
"filament/filament": "^3.2"
29+
"filament/support": "^3.2|^4.0",
30+
"filament/notifications": "^3.2|^4.0",
31+
"filament/filament": "^3.2|^4.0"
3232
},
3333
"extra": {
3434
"laravel": {

resources/css/commentions.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import "tailwindcss" source(none) prefix(comm) important;
22

3+
@source "../js/";
34
@source "../views/";
45
@source "../../src";
56

resources/dist/commentions.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.

resources/dist/commentions.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/commentions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ document.addEventListener('alpine:init', () => {
3030
],
3131
editorProps: {
3232
attributes: {
33-
class: `prose dark:prose-invert prose-sm sm:prose-base lg:prose-lg xl:prose-2xl focus:outline-none p-4 min-w-full w-full rounded-lg border border-gray-300 dark:border-gray-700`,
33+
class: `comm:prose comm:dark:prose-invert comm:prose-sm comm:sm:prose-base comm:lg:prose-lg comm:xl:prose-2xl comm:focus:outline-none comm:p-4 comm:min-w-full comm:w-full comm:rounded-lg comm:border comm:border-gray-300 comm:dark:border-gray-700`,
3434
},
3535
},
3636
placeholder: 'Type something...',

resources/views/comment-list.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div @if ($pollingInterval) wire:poll.{{ $pollingInterval }}s @endif>
1+
<div @if ($pollingInterval) wire:poll.{{ $pollingInterval }} @endif>
22
@if ($this->comments->isEmpty())
33
<div class="comm:flex comm:items-center comm:justify-center comm:p-6 comm:text-center comm:rounded-lg comm:border comm:border-dashed comm:border-gray-300 comm:dark:border-gray-700">
44
<div class="comm:flex comm:flex-col comm:items-center comm:gap-y-2">

resources/views/comment.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@use('\Kirschbaum\Commentions\Config')
22

3-
<div class="comm:flex comm:items-start comm:gap-x-4 comm:border comm:p-4 comm:rounded-lg comm:shadow-sm comm:mb-2" id="filament-comment-{{ $comment->getId() }}">
3+
<div class="comm:flex comm:items-start comm:gap-x-4 comm:border comm:dark:border-gray-700 comm:p-4 comm:rounded-lg comm:shadow-sm comm:mb-2" id="filament-comment-{{ $comment->getId() }}">
44
@if ($avatar = $comment->getAuthorAvatar())
55
<img
66
src="{{ $comment->getAuthorAvatar() }}"

src/Comment.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Closure;
77
use DateTime;
88
use Filament\Models\Contracts\HasAvatar;
9-
use Filament\Support\Facades\FilamentColor;
109
use Illuminate\Database\Eloquent\Casts\Attribute;
1110
use Illuminate\Database\Eloquent\Factories\HasFactory;
1211
use Illuminate\Database\Eloquent\Model;
@@ -20,7 +19,6 @@
2019
use Kirschbaum\Commentions\Contracts\Commenter;
2120
use Kirschbaum\Commentions\Contracts\RenderableComment;
2221
use Kirschbaum\Commentions\Database\Factories\CommentFactory;
23-
use Spatie\Color\Rgb;
2422

2523
/**
2624
* @property int $id
@@ -133,9 +131,7 @@ public function getAuthorAvatar(): string
133131
->map(fn (string $segment): string => filled($segment) ? mb_substr($segment, 0, 1) : '')
134132
->join(' ');
135133

136-
$backgroundColor = Rgb::fromString('rgb(' . FilamentColor::getColors()['gray'][950] . ')')->toHex();
137-
138-
return 'https://ui-avatars.com/api/?name=' . urlencode($name) . '&color=FFFFFF&background=' . str($backgroundColor)->after('#');
134+
return 'https://ui-avatars.com/api/?name=' . urlencode($name) . '&color=FFFFFF&background=71717b';
139135
}
140136

141137
public function getBody(): string

src/Filament/Concerns/HasPolling.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@
22

33
namespace Kirschbaum\Commentions\Filament\Concerns;
44

5+
use Closure;
6+
7+
/**
8+
* @deprecated to be removed when dropping support for Filament 3.
9+
*
10+
* Filament 4 has expanded the `CanPoll` trait which is included in Components
11+
* by default in such a way that it provides everything this trait needs to do.
12+
* This trait is replicating the new functionality of `CanPoll` so that we can
13+
* maintain compatibility with Filament 3.
14+
*/
515
trait HasPolling
616
{
7-
protected ?int $pollingInterval = null;
17+
protected string|Closure|null $pollingInterval = null;
818

19+
/**
20+
* @deprecated Use `poll` with a string instead, e.g. `poll('10s')`
21+
*/
922
public function pollingInterval(int $interval = 60): static
1023
{
1124
$this->pollingInterval = $interval;
1225

1326
return $this;
1427
}
1528

16-
public function getPollingInterval(): ?int
29+
public function poll(string|Closure|null $interval = '60s'): static
30+
{
31+
$this->pollingInterval = $interval;
32+
33+
return $this;
34+
}
35+
36+
public function getPollingInterval(): ?string
1737
{
18-
return $this->pollingInterval;
38+
return $this->evaluate($this->pollingInterval);
1939
}
2040
}

0 commit comments

Comments
 (0)