Skip to content

Commit bd31e36

Browse files
committed
General tweaks
1 parent 92d7696 commit bd31e36

File tree

13 files changed

+75
-210
lines changed

13 files changed

+75
-210
lines changed

.cursor/rules/filament-plugin.mdc

Lines changed: 0 additions & 13 deletions
This file was deleted.

config/commentions.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
<?php
22

33
return [
4-
/**
5-
* The table name.
6-
*/
7-
'table_name' => 'comments',
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Table name configurations
7+
|--------------------------------------------------------------------------
8+
*/
9+
'tables' => [
10+
'comments' => 'comments',
11+
'comment_reactions' => 'comment_reactions',
12+
],
813

9-
/**
10-
* The commenter config.
11-
*/
14+
/*
15+
|--------------------------------------------------------------------------
16+
| Commenter model configuration
17+
|--------------------------------------------------------------------------
18+
*/
1219
'commenter' => [
1320
'model' => \App\Models\User::class,
1421
],
1522

16-
/**
17-
* Comment editing/deleting options.
18-
*/
23+
/*
24+
|--------------------------------------------------------------------------
25+
| Comment Moderation
26+
|--------------------------------------------------------------------------
27+
*/
1928
'allow_edits' => true,
2029
'allow_deletes' => true,
2130

22-
/**
23-
* Allowed reactions for comments.
24-
* Define the list of emojis that users can react with.
25-
*/
26-
'allowed_reactions' => ['👍', '❤️', '😂', '😮', '😢', '🤔'],
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Reactions
34+
|--------------------------------------------------------------------------
35+
*/
36+
'reactions' => [
37+
'allowed' => ['👍', '❤️', '😂', '😮', '😢', '🤔'],
38+
],
2739
];

database/migrations/create_commentions_reactions_table.php.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ return new class extends Migration
88
{
99
public function up()
1010
{
11-
Schema::create('comment_reactions', function (Blueprint $table) {
11+
Schema::create(config('commentions.tables.comment_reactions', 'comment_reactions'), function (Blueprint $table) {
1212
$table->id();
1313
$table->foreignId('comment_id')->constrained(config('commentions.table_name'))->cascadeOnDelete();
1414
$table->morphs('reactor');
@@ -21,6 +21,6 @@ return new class extends Migration
2121

2222
public function down(): void
2323
{
24-
Schema::dropIfExists('comment_reactions');
24+
Schema::dropIfExists(config('commentions.tables.comment_reactions', 'comment_reactions'));
2525
}
2626
};

database/migrations/create_commentions_tables.php.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ return new class extends Migration
88
{
99
public function up()
1010
{
11-
Schema::create(config('commentions.table_name'), function (Blueprint $table) {
11+
Schema::create(config('commentions.tables.comments', 'comments'), function (Blueprint $table) {
1212
$table->id();
1313
$table->morphs('author');
1414
$table->morphs('commentable');
@@ -19,6 +19,6 @@ return new class extends Migration
1919

2020
public function down(): void
2121
{
22-
Schema::dropIfExists(config('commentions.table_name'));
22+
Schema::dropIfExists(config('commentions.tables.comments', 'comments'));
2323
}
2424
};

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/views/comment.blade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ class="text-xs text-gray-300 ml-1"
8181
@else
8282
<div class="mt-1 space-y-6 text-sm text-gray-800 dark:text-gray-200">{!! $comment->getParsedBody() !!}</div>
8383

84-
@if ($comment->isComment() && $comment instanceof \Kirschbaum\Commentions\Comment)
85-
<livewire:commentions::reaction-manager
84+
@if ($comment->isComment())
85+
<livewire:commentions::reactions
8686
:comment="$comment"
87-
{{-- :reaction-summary="$this->reactionSummary" --}}
8887
:wire:key="'reaction-manager-' . $comment->getId()"
8988
/>
9089
@endif

resources/views/reaction-manager.blade.php

Lines changed: 0 additions & 80 deletions
This file was deleted.

resources/views/reactions.blade.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
x-cloak
77
wire:click="handleReactionToggle('{{ $reactionData['reaction'] }}')"
88
type="button"
9-
class="inline-flex items-center justify-center gap-1 rounded-full border px-2 h-8 text-sm font-medium transition hover:bg-gray-100 dark:hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed
9+
class="inline-flex items-center justify-center gap-1 rounded-full border px-2 h-8 text-sm font-medium transition focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed
1010
{{ $reactionData['reacted_by_current_user']
11-
? 'bg-primary-100 dark:bg-primary-800 border-primary-300 dark:border-primary-600 text-primary-700 dark:text-primary-200'
12-
: 'bg-white dark:bg-gray-900 border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200' }}"
11+
? 'bg-primary-100 dark:bg-primary-800 border-primary-300 dark:border-primary-600 text-primary-700 dark:text-primary-200 hover:bg-primary-200 dark:hover:bg-primary-600'
12+
: 'bg-white dark:bg-gray-900 border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600' }}"
1313
title="{{ $reactionData['reaction'] }}"
1414

1515
>
@@ -25,7 +25,7 @@ class="inline-flex items-center justify-center gap-1 rounded-full border px-2 h-
2525
x-on:click="open = !open"
2626
type="button"
2727
@disabled(! auth()->check())
28-
class="inline-flex items-center justify-center gap-1 rounded-full border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 w-8 h-8 text-sm font-medium text-gray-700 dark:text-gray-200 transition hover:bg-gray-100 dark:hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed"
28+
class="inline-flex items-center justify-center gap-1 rounded-full border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 w-8 h-8 text-sm font-medium text-gray-700 dark:text-gray-200 transition hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed"
2929
title="Add Reaction"
3030
wire:key="add-reaction-button-{{ $comment->getId() }}"
3131
>
@@ -51,10 +51,10 @@ class="absolute bottom-full mb-2 z-10 bg-white dark:bg-gray-800 border border-gr
5151
x-on:click="open = false"
5252
type="button"
5353
@disabled(! auth()->check())
54-
class="inline-flex items-center justify-center gap-1 rounded-full border w-8 h-8 text-sm font-medium transition hover:bg-gray-100 dark:hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed
54+
class="inline-flex items-center justify-center gap-1 rounded-full border w-8 h-8 text-sm font-medium transition focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed
5555
{{ $reactionData['reacted_by_current_user']
56-
? 'bg-primary-100 dark:bg-primary-800 border-primary-300 dark:border-primary-600 text-primary-700 dark:text-primary-200'
57-
: 'bg-white dark:bg-gray-900 border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200' }}"
56+
? 'bg-primary-100 dark:bg-primary-800 border-primary-300 dark:border-primary-600 text-primary-700 dark:text-primary-200 hover:bg-primary-200 dark:hover:bg-primary-600'
57+
: 'bg-white dark:bg-gray-900 border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600' }}"
5858
title="{{ $reactionEmoji }}"
5959
wire:key="popup-reaction-button-{{ $reactionEmoji }}-{{ $comment->getId() }}"
6060
>
@@ -69,7 +69,7 @@ class="inline-flex items-center justify-center gap-1 rounded-full border w-8 h-8
6969
@if (! in_array($reactionEmoji, $allowedReactions) && $data['count'] > 0)
7070
<span
7171
wire:key="reaction-extra-{{ $reactionEmoji }}-{{ $comment->getId() }}"
72-
class="inline-flex items-center justify-center gap-1 rounded-full border border-gray-300 dark:border-gray-600 bg-gray-100 dark:bg-gray-800 w-8 h-8 text-sm font-medium text-gray-600 dark:text-gray-300"
72+
class="inline-flex items-center justify-center gap-1 rounded-full border border-gray-300 dark:border-gray-600 bg-gray-100 dark:bg-gray-800 px-2 h-8 text-sm font-medium text-gray-600 dark:text-gray-300"
7373
title="{{ $reactionEmoji }}"
7474
>
7575
<span>{{ $reactionEmoji }}</span>

src/Actions/ToggleCommentReaction.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,28 @@ public static function run(Comment $comment, string $reaction, ?Commenter $user
3030

3131
if ($existingReaction) {
3232
$existingReaction->delete();
33-
event(new CommentReactionToggledEvent($comment, $existingReaction, $user, $reaction, false));
33+
34+
event(new CommentReactionToggledEvent(
35+
comment: $comment,
36+
reaction: $existingReaction,
37+
user: $user,
38+
reactionType: $reaction,
39+
wasCreated: false
40+
));
3441
} else {
3542
$newReaction = $comment->reactions()->create([
3643
'reactor_id' => $user->getKey(),
3744
'reactor_type' => $user->getMorphClass(),
3845
'reaction' => $reaction,
3946
]);
40-
event(new CommentReactionToggledEvent($comment, $newReaction, $user, $reaction, true));
47+
48+
event(new CommentReactionToggledEvent(
49+
comment: $comment,
50+
reaction: $newReaction,
51+
user: $user,
52+
reactionType: $reaction,
53+
wasCreated: true
54+
));
4155
}
4256
}
4357
}

src/CommentionsServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use Spatie\LaravelPackageTools\Package;
99
use Filament\Support\Facades\FilamentAsset;
1010
use Kirschbaum\Commentions\Livewire\Comment;
11+
use Kirschbaum\Commentions\Livewire\Reactions;
1112
use Kirschbaum\Commentions\Livewire\Comments;
1213
use Kirschbaum\Commentions\Livewire\CommentList;
13-
use Kirschbaum\Commentions\Livewire\ReactionManager;
1414
use Spatie\LaravelPackageTools\PackageServiceProvider;
1515

1616
class CommentionsServiceProvider extends PackageServiceProvider
@@ -39,8 +39,8 @@ public function packageBooted(): void
3939
Livewire::component('commentions::comment', Comment::class);
4040
Livewire::component('commentions::comment-list', CommentList::class);
4141
Livewire::component('commentions::comments', Comments::class);
42-
Livewire::component('commentions::reaction-manager', ReactionManager::class);
43-
// Asset Registration
42+
Livewire::component('commentions::reactions', Reactions::class);
43+
4444
FilamentAsset::register(
4545
[
4646
Js::make('commentions-scripts', __DIR__ . '/../resources/dist/commentions.js'),

0 commit comments

Comments
 (0)