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
22 changes: 18 additions & 4 deletions config/nested-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,22 @@
'allow-multiple-reactions' => env('ALLOW_MULTIPLE_REACTIONS', false), // Allow multiple reactions from the same user
'allow-guest-reactions' => env('ALLOW_GUEST_REACTIONS', false), // Allow guest users to react
'allow-guest-comments' => env('ALLOW_GUEST_COMMENTS', false), // Allow guest users to comment
'mentions' => [
'items-placeholder' => 'Search users by name or email address',
'empty-items-message' => 'No users found',
],

'format-created-date' => 'F j Y h:i:s A',
/*
|--------------------------------------------------------------------------
| Livewire Component
|--------------------------------------------------------------------------
|
*/
'show-heading' => true,

'show-badge-counter' => true,
'badge-counter-color' => 'info',

'show-refresh-button' => true,
'style-refresh-button' => 'button', // 'button' or 'icon',
'icon-refresh-button' => 'heroicon-m-sparkles',
'outlined-refresh-button' => false,
'color-refresh-button' => 'info' // 'danger', 'gray', 'info', 'success' or 'warning'
];
52 changes: 51 additions & 1 deletion resources/lang/en/nested-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,55 @@

// translations for Coolsam/NestedComments
return [
//
'comments' => [
'general' => [
'guest' => 'Guest',
'no_comments_provided' => 'No comments provided.',
'no_commentable_record_set' => 'No Commentable record set.',
'record_is_not_configured_for_reactions' => 'The current record is not configured for reactions. Please include the `HasReactions` trait to the model.',
'no_commentable_record_found_widget' => 'No Commentable record found. Please pass a record to the widget.',
'reply' => 'Reply',
'no_replies' => 'No replies yet.',
'comments' => 'Comments',
],
'form' => [
'field' => [
'comment' => [
'label' => 'Your Comment',
'mention_items_placeholder' => 'Search users by name or email address',
'empty_mention_items_message' => 'No users found',

],
],
'buttons' => [
'submit' => 'Submit',
'cancel' => 'Cancel',
'add_comment' => 'Add a new comment',
'add_reply' => 'Add a reply',
'reply' => 'Reply',
'hide_replies' => 'Hide Replies',
'refresh' => 'Refresh',
]
],
'table' => [
'actions' => [
'view_comments' => [
//'label' => 'View comment',
'heading' => 'Comments',
'close' => 'Close'
]
],
],
'actions' => [
'view_comment' => [
//'label' => 'View comment',
'heading' => 'View Comments',
'close' => 'Close'
]
]
],
'reactions' => [
'add_reaction' => 'Add a reaction',
]

];
55 changes: 55 additions & 0 deletions resources/lang/fr/nested-comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

// translations for Coolsam/NestedComments
return [
'comments' => [
'general' => [
'guest' => 'Visiteur',
'no_comments_provided' => 'Aucun commentaire enregistré.',
'no_commentable_record_set' => 'Aucun `Commentable record` défini.',
'record_is_not_configured_for_reactions' => 'L\'enregistrement actuel n\'est pas configuré pour les réactions. Veuillez inclure le trait `HasReactions` au modèle.',
'no_commentable_record_found_widget' => 'Aucun `Commentable record` trouvé. Merci de passer le model au widget',
'reply' => 'Réponse',
'no_replies' => 'Aucune réponse.',
'comments' => 'Commentaires',
],
'form' => [
'field' => [
'comment' => [
'label' => '',
//'label' => 'Votre Commentaire',
'mention_items_placeholder' => 'Rechercher les utilisateurs par nom ou email',
'empty_mention_items_message' => 'Aucun utilisateur trouvé',

],
],
'buttons' => [
'submit' => 'Envoyer',
'cancel' => 'Fermer',
'add_comment' => 'Ajouter un nouveau commentaire',
'add_reply' => 'Ajouter une réponse',
'reply' => 'Répondre',
'hide_replies' => 'Cacher les réponses',
'refresh' => 'Rafraîchir',
]
],
'table' => [
'actions' => [
'view_comments' => [
'heading' => 'Commentaires',
'close' => 'Fermer'
]
],
],
'actions' => [
'view_comment' => [
'heading' => 'Voir les Commentaires',
'close' => 'Fermer'
]
]
],
'reactions' => [
'add_reaction' => 'Ajouter une réaction',
]

];
4 changes: 2 additions & 2 deletions resources/views/components/comment-card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
/>
@else
<p class="text-gray-500 dark:text-gray-400">
{{ __('No comment provided.') }}
{{ __('nested-comments::nested-comments.comments.general.no_comments_provided') }}
</p>
@endif
@endif
4 changes: 2 additions & 2 deletions resources/views/components/comments.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@if(isset($record))
<livewire:nested-comments::comments :record="$record" />
@else
<p>No Commentable record set.</p>
@endif
<p>{{ __('nested-comments::nested-comments.comments.general.no_commentable_record_set') }}</p>
@endif
4 changes: 2 additions & 2 deletions resources/views/components/reactions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
@if(app(\Coolsam\NestedComments\NestedComments::class)->classHasTrait($record, \Coolsam\NestedComments\Concerns\HasReactions::class))
<livewire:nested-comments::reaction-panel :record="$record"/>
@else
<p>__('The current record is not configured for reactions. Please include the `HasReactions` trait to the model.')</p>
<p>{{ __('nested-comments::nested-comments.comments.general.record_is_not_configured_for_reactions') }}</p>
@endif
@endif
@endif
2 changes: 1 addition & 1 deletion resources/views/filament/widgets/comments-widget.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<livewire:nested-comments::comments :record="$this->record" />
@else
<x-filament::section>
No Commentable record found. Please pass a record to the widget.
{{ __('nested-comments::nested-comments.comments.general.no_commentable_record_found_widget') }}
</x-filament::section>
@endif
</x-filament-widgets::widget>
6 changes: 3 additions & 3 deletions resources/views/livewire/add-comment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
<form wire:submit.prevent="create" wire:loading.attr="disabled" class="space-y-4">
{{ $this->form }}
<x-filament::button type="submit">
Submit
{{ __('nested-comments::nested-comments.comments.form.buttons.submit') }}
</x-filament::button>
<x-filament::button type="button" color="gray" wire:click="showForm(false)">
Cancel
{{ __('nested-comments::nested-comments.comments.form.buttons.cancel') }}
</x-filament::button>
</form>
@else
<x-filament::input.wrapper
:inline-prefix="true"
prefix-icon="heroicon-o-chat-bubble-bottom-center-text">
<x-filament::input
:placeholder="$this->replyTo?->getKey() ? 'Add a reply' : 'Add a new comment'"
:placeholder="$this->replyTo?->getKey() ? __('nested-comments::nested-comments.comments.form.buttons.add_reply') : __('nested-comments::nested-comments.comments.form.buttons.add_comment')"
type="text"
wire:click.prevent.stop="showForm(true)"
:readonly="true"
Expand Down
12 changes: 6 additions & 6 deletions resources/views/livewire/comment-card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class="text-xs text-gray-500 dark:text-gray-400">
</p>
<p x-show="showFullDate"
class="text-xs text-gray-500 dark:text-gray-400"
>{{ $this->comment->created_at->format('F j Y h:i:s A') }}</p>
>{{ $this->comment->created_at->format(config('nested-comments.format-created-date', 'F j Y h:i:s A')) }}</p>
</div>
</div>
</div>
Expand All @@ -34,11 +34,11 @@ class="cursor-pointer"
wire:click.prevent="toggleReplies">
@if($this->comment->replies_count > 0)
<span title="{{ \Illuminate\Support\Number::format($this->comment->replies_count) }}">
{{\Illuminate\Support\Number::forHumans($this->comment->replies_count, maxPrecision: 3, abbreviate: true)}} {{ str('Reply')->plural($this->comment->replies_count) }}
{{\Illuminate\Support\Number::forHumans($this->comment->replies_count, maxPrecision: 3, abbreviate: true)}} {{ str(__('nested-comments::nested-comments.comments.general.reply'))->plural($this->comment->replies_count) }}
</span>
@else
<span title="{{__('No replies yet')}}">
Reply
<span title="{{ __('nested-comments::nested-comments.comments.general.no_replies') }}">
{{ __('nested-comments::nested-comments.comments.form.buttons.reply') }}
</span>
@endif
</x-filament::link>
Expand Down Expand Up @@ -67,7 +67,7 @@ class="cursor-pointer"
}
"
type="button"
label="Hide replies" icon="heroicon-o-minus-circle" class="absolute -left-8 -bottom-4" wire:click.prevent="toggleReplies"/>
label="{{ __('nested-comments::nested-comments.comments.form.buttons.hide_replies') }}" tooltip="{{ __('nested-comments::nested-comments.comments.form.buttons.hide_replies') }}" icon="heroicon-o-minus-circle" class="absolute -left-8 -bottom-4" wire:click.prevent="toggleReplies"/>
</div>
@endif
</div>
Expand All @@ -79,4 +79,4 @@ class="cursor-pointer"
element.classList.add(['comment-mention']);
});
</script>
@endscript
@endscript
44 changes: 30 additions & 14 deletions resources/views/livewire/comments.blade.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
<x-filament::section wire:poll.10s :compact="true" class="!ring-0 !shadow-none !p-0">
<x-slot name="heading">
<div class="flex items-center space-x-2">
<div>
{{ __('Comments') }}
@if(config('nested-comments.show-heading', true))
<x-slot name="heading">
<div class="flex items-center space-x-2">
<div>
{{ __('nested-comments::nested-comments.comments.general.comments') }}
</div>
@if(config('nested-comments.show-badge-counter', true))
<div>
<x-filament::badge :color="config('nested-comments.badge-counter-color', 'danger')" :title="$this->comments->count()">
{{\Illuminate\Support\Number::forHumans($this->comments->count(),maxPrecision: 3, abbreviate: true)}}
</x-filament::badge>
</div>
@endif
</div>
<div>
<x-filament::badge color="danger" :title="$this->comments->count()">
{{\Illuminate\Support\Number::forHumans($this->comments->count(),maxPrecision: 3, abbreviate: true)}}
</x-filament::badge>
</div>
</div>
</x-slot>
<x-slot name="headerEnd">
<x-filament::button wire:click.prevent="refreshComments()">Refresh</x-filament::button>
</x-slot>
</x-slot>
@endif
@if(config('nested-comments.show-refresh-button', true))
<x-slot name="headerEnd">
<x-filament::button
wire:click.prevent="refreshComments()"
:color="config('nested-comments.color-refresh-button')"
:icon="config('nested-comments.icon-refresh-button')"
:outlined="config('nested-comments.outlined-refresh-button')"
:tooltip="config('nested-comments.style-refresh-button', 'button') === 'icon' ? __('nested-comments::nested-comments.comments.form.buttons.refresh') : null"
>
@if(config('nested-comments.style-refresh-button', 'button') === 'button')
{{ __('nested-comments::nested-comments.comments.form.buttons.refresh') }}
@endif
</x-filament::button>
</x-slot>
@endif
@foreach($this->comments as $comment)
<livewire:nested-comments::comment-card
:key="$comment->getKey()"
Expand Down
15 changes: 6 additions & 9 deletions resources/views/livewire/reaction-panel.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'font-light' => true,
])
title="{{$reaction}} {{collect($attribs)->get('reactions')}} {{str(collect($attribs)->get('name'))->plural(collect($attribs)->get('reactions'))}}"
tooltip="{{$reaction}} {{collect($attribs)->get('reactions')}} {{str(collect($attribs)->get('name'))->plural(collect($attribs)->get('reactions'))}}"
:outlined="true"
:color="collect($attribs)->get('meToo') ? 'primary' : 'gray'" size="xs"
>
Expand All @@ -14,7 +15,7 @@
@endforeach
<x-filament::dropdown placement="bottom-start">
<x-slot name="trigger">
<x-filament::button outlined color="gray" badge="+" size="xs" title="Add reaction">
<x-filament::button outlined color="gray" badge="+" size="xs" title="{{ __('nested-comments::nested-comments.reactions.add_reaction') }}" tooltip="{{ __('nested-comments::nested-comments.reactions.add_reaction') }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="size-4">
<path stroke-linecap="round" stroke-linejoin="round"
Expand All @@ -29,18 +30,14 @@
@class([
'font-light' => true,
])
:outlined="true" :color="collect($attribs)->get('meToo') ? 'primary' : 'gray'" size="md" title="{{collect($attribs)->get('name')}}"
:outlined="true"
:color="collect($attribs)->get('meToo') ? 'primary' : 'gray'"
size="md"
title="{{collect($attribs)->get('name')}}"
>
<span class="text-lg">{{$reaction}}</span>
</x-filament::button>
@endforeach
</div>
</x-filament::dropdown>
</div>
@script
<script>
function addReaction(reaction) {
console.log('About to add a reaction:', reaction);
}
</script>
@endscript
8 changes: 4 additions & 4 deletions src/Concerns/HasComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ public function deleteComment(Comment $comment): ?bool
$allowGuest = config('nested-comments.allow-guest-comments', false);

if (! auth()->check() && ! $allowGuest) {
throw new Exception('You must be logged in to edit your comment.');
throw new Exception('You must be logged in to delete your comment.');
}

if (auth()->check() && $comment->getAttribute('user_id') !== auth()->id()) {
throw new Exception('You are not authorized to edit this comment.');
throw new Exception('You are not authorized to delete this comment.');
}

if ($allowGuest && ! auth()->check()) {
$guestId = app(NestedComments::class)->getGuestId();
if ($comment->getAttribute('guest_id') !== $guestId) {
throw new Exception('You are not authorized to edit this comment.');
throw new Exception('You are not authorized to delete this comment.');
}
}

Expand All @@ -149,7 +149,7 @@ final public function getUserNameUsing(Comment $comment): string

final public function getUserAvatarUsing(Comment $comment): ?string
{
$user = $comment->user ?? $comment->guest_name ?? 'Guest';
$user = $comment->user ?? $comment->guest_name ?? __('nested-comments::nested-comments.comments.general.guest');

return $this->getUserAvatar($user);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Filament/Actions/CommentsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ protected function setUp(): void
parent::setUp();
$this->modalWidth('4xl')
->slideOver()
->modalHeading(fn (): string => __('View Comments'));
->modalHeading(fn (): string => __('nested-comments::nested-comments.comments.actions.view_comment.heading'));
$this->modalSubmitAction(false);
$this->modalCancelActionLabel(__('Close'));
$this->modalCancelActionLabel(__('nested-comments::nested-comments.comments.actions.view_comment.close'));
$this->icon('heroicon-o-chat-bubble-left-right');
$this->modalIcon('heroicon-o-chat-bubble-left-right');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Filament/Infolists/CommentCardEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function evaluateUserAvatar(): ?string
return $this->evaluate($this->userAvatarUsingClosure
?? fn (Comment | Model $record) => app(NestedComments::class)
->getDefaultUserAvatar($record->getAttribute('user')
?? $record->getAttribute('guest_name') ?? 'Guest'));
?? $record->getAttribute('guest_name') ?? __('nested-comments::nested-comments.comments.general.guest')));
}

public function evaluateUserName(): ?string
Expand Down
4 changes: 2 additions & 2 deletions src/Filament/Tables/Actions/CommentsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ protected function setUp(): void
parent::setUp();
$this->modalWidth('4xl')
->slideOver()
->modalHeading(fn (): string => __('Comments'));
->modalHeading(fn (): string => __('nested-comments::nested-comments.comments.table.actions.view_comments.heading'));
$this->modalSubmitAction(false);
$this->modalCancelActionLabel(__('Close'));
$this->modalCancelActionLabel(__('nested-comments::nested-comments.comments.table.actions.view_comments.close'));
$this->icon('heroicon-o-chat-bubble-left-right');
$this->modalIcon('heroicon-o-chat-bubble-left-right');
}
Expand Down
Loading