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
3 changes: 2 additions & 1 deletion resources/views/comment-list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<livewire:commentions::comment
<livewire:dynamic-component
:component="$commentionsComponentPrefix . 'comment'"
:key="$comment->getContentHash()"
:comment="$comment"
:mentionables="$mentionables"
Expand Down
3 changes: 2 additions & 1 deletion resources/views/comment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class="comm:text-xs comm:text-gray-300 comm:ml-1"
<div class="comm:mt-1 comm:space-y-6 comm:text-sm comm:text-gray-800 comm:dark:text-gray-200">{!! $comment->getParsedBody() !!}</div>

@if ($comment->isComment())
<livewire:commentions::reactions
<livewire:dynamic-component
:component="$commentionsComponentPrefix . 'reactions'"
:comment="$comment"
:wire:key="'reaction-manager-' . $comment->getId()"
/>
Expand Down
3 changes: 2 additions & 1 deletion resources/views/comments-modal.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div>
<livewire:commentions::comments
<livewire:dynamic-component
:component="$commentionsComponentPrefix . 'comments'"
:key="'comments-modal'"
:record="$record"
:mentionables="$mentionables"
Expand Down
6 changes: 4 additions & 2 deletions resources/views/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</form>
@endif

<livewire:commentions::comment-list
<livewire:dynamic-component
:component="$commentionsComponentPrefix . 'comment-list'"
:record="$record"
:mentionables="$this->mentions"
:polling-interval="$pollingInterval"
Expand All @@ -46,7 +47,8 @@

{{-- Subscription Sidebar --}}
@if ($this->canSubscribe && $this->resolvedSidebarEnabled)
<livewire:commentions::subscription-sidebar
<livewire:dynamic-component
:component="$commentionsComponentPrefix . 'subscription-sidebar'"
:record="$record"
:show-subscribers="$this->resolvedShowSubscribers"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
<livewire:commentions::comments
<livewire:dynamic-component
:component="$commentionsComponentPrefix . 'comments'"
:record="$getRecord()"
:mentionables="$getMentionables()"
:polling-interval="$getPollingInterval()"
Expand Down
30 changes: 11 additions & 19 deletions src/CommentionsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Kirschbaum\Commentions;

use Composer\InstalledVersions;
use Filament\Support\Assets\Css;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\View;
use Kirschbaum\Commentions\Comment as CommentModel;
use Kirschbaum\Commentions\Events\UserWasMentionedEvent;
use Kirschbaum\Commentions\Listeners\SendUserMentionedNotification;
Expand Down Expand Up @@ -45,15 +45,16 @@ public function configurePackage(Package $package): void

public function packageBooted(): void
{
if ($this->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(
[
Expand Down Expand Up @@ -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',
'>='
);
}
}
15 changes: 15 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kirschbaum\Commentions;

use Closure;
use Composer\InstalledVersions;
use InvalidArgumentException;
use Kirschbaum\Commentions\Contracts\Commenter;

Expand Down Expand Up @@ -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',
'>='
);
}
}
4 changes: 2 additions & 2 deletions src/Livewire/Concerns/HasSidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down