From b8e891dc9e47e9011ce4fa5f4af31fef9a0e686c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Dalmolin?= Date: Mon, 9 Feb 2026 10:39:12 -0300 Subject: [PATCH] Fixed tests for Livewire v4 --- resources/views/comment-list.blade.php | 3 +- resources/views/comment.blade.php | 3 +- resources/views/comments-modal.blade.php | 3 +- resources/views/comments.blade.php | 6 ++-- .../components/comments-entry.blade.php | 3 +- src/CommentionsServiceProvider.php | 30 +++++++------------ src/Config.php | 15 ++++++++++ src/Livewire/Concerns/HasSidebar.php | 4 +-- 8 files changed, 40 insertions(+), 27 deletions(-) diff --git a/resources/views/comment-list.blade.php b/resources/views/comment-list.blade.php index bef0d29..6ecbf31 100644 --- a/resources/views/comment-list.blade.php +++ b/resources/views/comment-list.blade.php @@ -15,7 +15,8 @@ class="comm:w-8 comm:h-8 comm:text-gray-400 comm:dark:text-gray-500" @endif @foreach ($this->comments as $comment) - {!! $comment->getParsedBody() !!} @if ($comment->isComment()) - diff --git a/resources/views/comments-modal.blade.php b/resources/views/comments-modal.blade.php index b241cc0..30560b9 100644 --- a/resources/views/comments-modal.blade.php +++ b/resources/views/comments-modal.blade.php @@ -1,5 +1,6 @@
- @endif - canSubscribe && $this->resolvedSidebarEnabled) - diff --git a/resources/views/filament/infolists/components/comments-entry.blade.php b/resources/views/filament/infolists/components/comments-entry.blade.php index 3884c78..9af985c 100644 --- a/resources/views/filament/infolists/components/comments-entry.blade.php +++ b/resources/views/filament/infolists/components/comments-entry.blade.php @@ -1,5 +1,6 @@ - isLivewireV4() && method_exists(Livewire::class, 'addNamespace')) { - Livewire::addNamespace('commentions', classNamespace: __NAMESPACE__ . '\\Livewire'); - } else { - Livewire::component('commentions::comment', Comment::class); - Livewire::component('commentions::comment-list', CommentList::class); - Livewire::component('commentions::comments', Comments::class); - Livewire::component('commentions::reactions', Reactions::class); - Livewire::component('commentions::subscription-sidebar', SubscriptionSidebar::class); - } + $prefix = Config::getComponentPrefix(); + + Livewire::component($prefix . 'comment', Comment::class); + Livewire::component($prefix . 'comment-list', CommentList::class); + Livewire::component($prefix . 'comments', Comments::class); + Livewire::component($prefix . 'reactions', Reactions::class); + Livewire::component($prefix . 'subscription-sidebar', SubscriptionSidebar::class); + + // Share component prefix with views for dynamic component names + View::share('commentionsComponentPrefix', $prefix); FilamentAsset::register( [ @@ -81,13 +82,4 @@ public function packageBooted(): void Event::listen(UserWasMentionedEvent::class, $listenerClass); } } - - protected function isLivewireV4(): bool - { - return version_compare( - InstalledVersions::getVersion('livewire/livewire') ?? '0.0', - '4.0', - '>=' - ); - } } diff --git a/src/Config.php b/src/Config.php index 7f9038a..052a2e2 100644 --- a/src/Config.php +++ b/src/Config.php @@ -3,6 +3,7 @@ namespace Kirschbaum\Commentions; use Closure; +use Composer\InstalledVersions; use InvalidArgumentException; use Kirschbaum\Commentions\Contracts\Commenter; @@ -94,4 +95,18 @@ public static function getTipTapCssClasses(): ?string return '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'; } + + public static function getComponentPrefix(): string + { + return static::isLivewireV4() ? 'commentions.' : 'commentions::'; + } + + public static function isLivewireV4(): bool + { + return version_compare( + InstalledVersions::getVersion('livewire/livewire') ?? '0.0', + '4.0', + '>=' + ); + } } diff --git a/src/Livewire/Concerns/HasSidebar.php b/src/Livewire/Concerns/HasSidebar.php index 25a5684..6d073d4 100644 --- a/src/Livewire/Concerns/HasSidebar.php +++ b/src/Livewire/Concerns/HasSidebar.php @@ -17,7 +17,7 @@ trait HasSidebar public function mountHasSidebar(?bool $enableSidebar = null, ?bool $showSubscribers = null): void { - $this->sidebarEnabled = $enableSidebar ?? config('commentions.subscriptions.show_sidebar'); + $this->sidebarEnabled = $enableSidebar ?? (bool) config('commentions.subscriptions.show_sidebar'); $this->showSubscribers = $showSubscribers ?? (bool) config('commentions.subscriptions.show_subscribers', true); } @@ -92,7 +92,7 @@ public function toggleSubscription(): void $this->refreshSubscribers(); - $this->dispatch('commentions:subscription:toggled')->to('commentions::subscription-sidebar'); + $this->dispatch('commentions:subscription:toggled')->to(Config::getComponentPrefix() . 'subscription-sidebar'); } protected function getCurrentUser(): ?Commenter