|
3 | 3 | namespace Tapp\FilamentForum\Filament\Resources\Forums\Pages; |
4 | 4 |
|
5 | 5 | use BackedEnum; |
| 6 | +use Filament\Actions\Action; |
6 | 7 | use Filament\Actions\CreateAction; |
7 | 8 | use Filament\Panel; |
8 | 9 | use Filament\Resources\Pages\ManageRelatedRecords; |
9 | 10 | use Filament\Tables\Table; |
10 | 11 | use Illuminate\Contracts\Support\Htmlable; |
| 12 | +use Illuminate\Support\Facades\Auth; |
11 | 13 | use Tapp\FilamentForum\Filament\Resources\ForumPosts\ForumPostResource; |
12 | 14 | use Tapp\FilamentForum\Filament\Resources\ForumPosts\Tables\ForumPostsTable; |
13 | 15 | use Tapp\FilamentForum\Filament\Resources\Forums\ForumResource; |
| 16 | +use Tapp\FilamentForum\Models\Forum; |
14 | 17 | use Tapp\FilamentForum\Models\ForumPost; |
15 | 18 |
|
16 | 19 | class ManageForumPosts extends ManageRelatedRecords |
@@ -43,15 +46,35 @@ public function table(Table $table): Table |
43 | 46 | { |
44 | 47 | return ForumPostsTable::configure($table) |
45 | 48 | ->headerActions([ |
| 49 | + Action::make('subscription') |
| 50 | + ->label(fn (): string => $this->forumSubscriptionRecord()->isSubscribed() |
| 51 | + ? __('filament-forum::filament-forum.forum.unsubscribe') |
| 52 | + : __('filament-forum::filament-forum.forum.subscribe')) |
| 53 | + ->icon(fn (): string => $this->forumSubscriptionRecord()->isSubscribed() ? 'heroicon-s-bell' : 'heroicon-o-bell') |
| 54 | + ->visible(fn (): bool => Auth::check()) |
| 55 | + ->action(fn () => $this->toggleForumSubscription()), |
46 | 56 | CreateAction::make(), |
47 | 57 | ]); |
48 | 58 | } |
49 | 59 |
|
| 60 | + public function toggleForumSubscription(): void |
| 61 | + { |
| 62 | + $this->forumSubscriptionRecord()->toggleSubscription(); |
| 63 | + } |
| 64 | + |
50 | 65 | public function toggleFavorite($recordId) |
51 | 66 | { |
52 | 67 | $forumPostrecord = ForumPost::find($recordId); |
53 | 68 | $forumPostrecord->toggleFavorite(); |
54 | 69 |
|
55 | 70 | $this->dispatch('favorite-toggled', recordId: $recordId, isFavorite: $forumPostrecord->isFavorite()); |
56 | 71 | } |
| 72 | + |
| 73 | + protected function forumSubscriptionRecord(): Forum |
| 74 | + { |
| 75 | + /** @var Forum $forum */ |
| 76 | + $forum = $this->getOwnerRecord(); |
| 77 | + |
| 78 | + return $forum; |
| 79 | + } |
57 | 80 | } |
0 commit comments