Update comments design

This commit is contained in:
2026-05-24 14:49:46 +02:00
parent f5c706b587
commit 9fc9e8ed10
2 changed files with 311 additions and 175 deletions

View File

@@ -1,110 +1,189 @@
<div>
<div class="flex" id="comment-{{ $comment->id }}">
<div class="flex-shrink-0 mr-4">
<div id="comment-{{ $comment->id }}">
<div class="group flex gap-4">
{{-- Avatar --}}
<div class="shrink-0">
@if($comment->isDeletedByModerator())
<img class="h-10 w-10 rounded-full" src="{{ asset('images/default-avatar.webp') }}" alt="Deleted comment">
<img
class="h-10 w-10 rounded-full object-cover opacity-60"
src="{{ asset('images/default-avatar.webp') }}"
alt="Deleted comment"
>
@else
<img class="h-10 w-10 rounded-full" src="{{ $comment->user->getAvatar() }}" alt="{{ $comment->user->name }}">
<img
class="h-10 w-10 rounded-full object-cover ring-2 ring-white dark:ring-neutral-800"
src="{{ $comment->user->getAvatar() }}"
alt="{{ $comment->user->name }}"
>
@endif
</div>
<div class="flex-grow">
<div class="flex gap-2">
{{-- Content --}}
<div class="min-w-0 flex-1">
<div class="rounded-2xl border border-neutral-200 bg-white px-5 py-4 shadow-sm transition group-hover:border-neutral-300 dark:border-neutral-800 dark:bg-neutral-800 dark:group-hover:border-neutral-700">
{{-- Header --}}
<div class="mb-3 flex flex-wrap items-center gap-2">
@if($comment->isDeletedByModerator())
<span class="font-semibold text-neutral-900 dark:text-neutral-100">
@if (Auth::check() && (Auth::user()->hasRole(\App\Enums\UserRole::ADMINISTRATOR) || Auth::user()->hasRole(\App\Enums\UserRole::MODERATOR)))
<p class="font-medium text-gray-900 dark:text-gray-100">Deleted ({{ $comment->user->name }})</p>
Deleted ({{ $comment->user->name }})
@else
<p class="font-medium text-gray-900 dark:text-gray-100">Deleted</p>
Deleted
@endif
</span>
@else
<p class="font-medium text-gray-900 dark:text-gray-100">{{ $comment->user->name }}</p>
<span class="font-semibold text-neutral-900 dark:text-neutral-100">
{{ $comment->user->name }}
</span>
@endif
{{-- Badges --}}
@if($comment->user->hasRole(\App\Enums\UserRole::ADMINISTRATOR))
<a data-te-toggle="tooltip" title="Admin"><i class="fa-solid fa-crown text-yellow-600"></i></a>
<span class="inline-flex items-center rounded-full bg-yellow-100 px-2 py-0.5 text-xs font-medium text-yellow-700 dark:bg-yellow-500/10 dark:text-yellow-400">
<i class="fa-solid fa-crown mr-1"></i>
Admin
</span>
@endif
@if($comment->user->hasRole(\App\Enums\UserRole::MODERATOR))
<a data-te-toggle="tooltip" title="Admin" class="text-rose-600">Moderator</a>
<span class="inline-flex items-center rounded-full bg-rose-100 px-2 py-0.5 text-xs font-medium text-rose-700 dark:bg-rose-500/10 dark:text-rose-400">
Moderator
</span>
@endif
@if($comment->user->hasRole(\App\Enums\UserRole::SUPPORTER))
<a data-te-toggle="tooltip" title="Badge of appreciation for the horny people supporting us! :3"><i class="fa-solid fa-hand-holding-heart text-rose-600"></i></a>
<span class="inline-flex items-center rounded-full bg-pink-100 px-2 py-0.5 text-xs font-medium text-pink-700 dark:bg-pink-500/10 dark:text-pink-400">
<i class="fa-solid fa-heart mr-1"></i>
Supporter
</span>
@endif
</div>
<div class="mt-1 flex-grow w-full">
{{-- Body --}}
<div class="prose prose-sm max-w-none dark:prose-invert">
@if($comment->isDeletedByModerator())
<div class="text-gray-700 dark:text-gray-200">Deleted by moderation.</div>
<p class="italic text-neutral-500 dark:text-neutral-400">
Deleted by moderation.
</p>
@if (Auth::check() && (Auth::user()->hasRole(\App\Enums\UserRole::ADMINISTRATOR) || Auth::user()->hasRole(\App\Enums\UserRole::MODERATOR)))
<div class="text-gray-700 dark:text-gray-300 pt-1">Original comment: {!! $comment->presenter()->markdownBody() !!}</div>
@endif
@else
@if ($isEditing)
<form wire:submit.prevent="editComment">
<div>
<label for="comment" class="sr-only">Comment body</label>
<textarea id="comment" name="comment" rows="3"
class="bg-white dark:bg-neutral-700 shadow-sm block w-full focus:ring-rose-500 focus:border-rose-500 border-gray-300 dark:border-gray-400/40 text-gray-900 dark:text-gray-200 placeholder:text-gray-400 rounded-md
@error('editState.body') border-red-500 @enderror"
placeholder="Write something" wire:model.defer="editState.body"></textarea>
@error('editState.body')
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
@enderror
<div class="mt-3 rounded-xl bg-neutral-100 p-3 text-sm dark:bg-neutral-800">
{!! $comment->presenter()->markdownBody() !!}
</div>
<div class="mt-3 flex items-center justify-between">
<button type="submit"
class="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-md shadow-sm text-white bg-rose-600 hover:bg-rose-700 focus:outline-none focus:ring-2 focus:ring-rose-500">
Edit
@endif
@else
@if ($isEditing)
<form wire:submit.prevent="editComment" class="space-y-4">
<textarea
rows="4"
wire:model.defer="editState.body"
class="w-full rounded-2xl border border-neutral-300 bg-white px-4 py-3 text-sm text-neutral-900 shadow-sm transition focus:border-rose-500 focus:outline-none focus:ring-4 focus:ring-rose-500/10 dark:border-neutral-700 dark:bg-neutral-950 dark:text-neutral-100 @error('editState.body') border-red-500 @enderror"
></textarea>
@error('editState.body')
<p class="text-sm text-red-500">
{{ $message }}
</p>
@enderror
<div class="flex justify-end">
<button
type="submit"
class="rounded-xl bg-rose-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-rose-700"
>
Save Changes
</button>
</div>
</form>
@else
<div class="text-gray-700 dark:text-gray-200">{!! $comment->presenter()->markdownBody() !!}</div>
@endif
@endif
<div class="text-gray-700 dark:text-gray-200">
{!! $comment->presenter()->markdownBody() !!}
</div>
<div class="mt-2 space-x-2 flex flex-row">
<span class="text-gray-500 dark:text-gray-300">
@endif
@endif
</div>
{{-- Footer --}}
<div class="mt-4 flex flex-wrap items-center gap-4 text-sm">
<span class="text-neutral-500 dark:text-neutral-400">
{{ $comment->presenter()->relativeCreatedAt() }}
</span>
{{-- Like --}}
@guest
<span data-te-toggle="tooltip" title="Please login to like the episode" class="text-gray-800 cursor-pointer dark:text-gray-200">
<i class="fa-regular fa-heart"></i> {{ $comment->likeCount() }}
<span class="flex items-center gap-1 text-neutral-500 dark:text-neutral-400">
<i class="fa-regular fa-heart"></i>
{{ $comment->likeCount() }}
</span>
@endguest
@auth
<!-- Like Button -->
<button class="text-gray-800 dark:text-gray-200 leading-tight cursor-pointer whitespace-nowrap" wire:click="like">
<button
wire:click="like"
class="flex items-center gap-1 text-neutral-500 transition hover:text-rose-600 dark:text-neutral-400 dark:hover:text-rose-400"
>
@if ($liked)
<i class="fa-solid fa-heart text-rose-600"></i> {{ $likeCount }}
<i class="fa-solid fa-heart text-rose-600"></i>
@else
<i class="fa-solid fa-heart"></i> {{ $likeCount }}
<i class="fa-regular fa-heart"></i>
@endif
{{ $likeCount }}
</button>
@endauth
{{-- Actions --}}
@auth
@if ($comment->depth() < 2)
<button wire:click="$toggle('isReplying')" type="button" class="text-gray-900 dark:text-gray-100 font-medium">
<button
wire:click="$toggle('isReplying')"
class="font-medium text-neutral-600 transition hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-neutral-100"
>
Reply
</button>
@endif
@can ('update', $comment)
<button wire:click="$toggle('isEditing')" type="button" class="text-gray-900 dark:text-gray-100 font-medium">
<button
wire:click="$toggle('isEditing')"
class="font-medium text-neutral-600 transition hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-neutral-100"
>
Edit
</button>
@endcan
@can ('destroy', $comment)
<button x-data="{
<button
x-data="{
confirmCommentDeletion () {
if (window.confirm('Are you sure you want to delete this comment?')) {
if (window.confirm('Delete this comment?')) {
@this.call('deleteComment');
}
}
}"
@click="confirmCommentDeletion"
type="button"
class="text-gray-900 dark:text-gray-100 font-medium"
class="font-medium text-red-500 transition hover:text-red-600"
>
Delete
</button>
@@ -113,41 +192,62 @@
@can ('restore', $comment)
<button
wire:click="restoreComment"
type="button"
class="text-gray-900 dark:text-gray-100 font-medium"
class="font-medium text-emerald-600 transition hover:text-emerald-700"
>
Restore
</button>
@endcan
@endauth
</div>
</div>
</div>
<div class="ml-14 mt-6">
@if ($isReplying)
<form wire:submit.prevent="postReply" class="my-4">
<div>
<label for="comment" class="sr-only">Reply body</label>
<textarea id="comment" name="comment" rows="3"
class="bg-white dark:bg-neutral-700 shadow-sm block w-full focus:ring-rose-500 focus:border-rose-500 border-gray-300 dark:border-gray-400/40 text-gray-900 dark:text-gray-200 placeholder:text-gray-400 rounded-md
@error('replyState.body') border-red-500 @enderror"
placeholder="Write something" wire:model.defer="replyState.body"></textarea>
@error('replyState.body')
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
@enderror
</div>
<div class="mt-3 flex items-center justify-between">
<button type="submit"
class="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-md shadow-sm text-white bg-rose-600 hover:bg-rose-700 focus:outline-none focus:ring-2 focus:ring-rose-500">
Comment
{{-- Reply Form --}}
@if ($isReplying)
<div class="mt-4 ml-2">
<form wire:submit.prevent="postReply" class="space-y-4">
<textarea
rows="3"
wire:model.defer="replyState.body"
placeholder="Write a reply..."
class="w-full rounded-2xl border border-neutral-300 bg-white px-4 py-3 text-sm text-neutral-900 shadow-sm transition focus:border-rose-500 focus:outline-none focus:ring-4 focus:ring-rose-500/10 dark:border-neutral-700 dark:bg-neutral-950 dark:text-neutral-100 @error('replyState.body') border-red-500 @enderror"
></textarea>
@error('replyState.body')
<p class="text-sm text-red-500">
{{ $message }}
</p>
@enderror
<div class="flex justify-end">
<button
type="submit"
class="rounded-xl bg-rose-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-rose-700"
>
Reply
</button>
</div>
</form>
</div>
@endif
{{-- Replies --}}
@if ($comment->children->count())
<div class="mt-2 space-y-2 border-l-2 border-neutral-200 pl-6 dark:border-neutral-700">
@foreach ($comment->children as $child)
<livewire:comment :comment="$child" :key="$child->id"/>
@endforeach
</div>
@endif
</div>
</div>
</div>

View File

@@ -1,57 +1,93 @@
<section>
<div class="bg-white dark:bg-neutral-800 shadow sm:rounded-xl sm:overflow-hidden">
<div class="px-4 py-5 sm:px-6">
<h2 class="leading-normal font-bold text-lg text-gray-900 dark:text-gray-200">Comments</h2>
<div class="overflow-hidden rounded-2xl border border-neutral-200 bg-white shadow-sm dark:border-neutral-800 dark:bg-neutral-900">
{{-- Header --}}
<div class="border-b border-neutral-200 px-6 py-5 dark:border-neutral-800">
<h2 class="text-xl font-semibold tracking-tight text-neutral-900 dark:text-neutral-100">
Comments
</h2>
</div>
<div>
<!-- Comment Input -->
<div class="bg-gray-50 dark:bg-neutral-800 px-4 py-6 sm:px-6 border-t border-b dark:border-neutral-950 border-neutral-200">
{{-- Comment Form --}}
<div class="border-b border-neutral-200 bg-neutral-50/80 px-6 py-6 dark:border-neutral-800 dark:bg-neutral-950/40">
@auth
<div class="flex">
<div class="flex-shrink-0 mr-4">
<img class="h-10 w-10 rounded-full" src="{{ auth()->user()->getAvatar() }}" alt="{{ auth()->user()->name }}">
</div>
<div class="min-w-0 flex-1">
<form wire:submit.prevent="postComment">
<div class="flex gap-4">
<img
class="h-11 w-11 rounded-full object-cover ring-2 ring-white dark:ring-neutral-800"
src="{{ auth()->user()->getAvatar() }}"
alt="{{ auth()->user()->name }}"
>
<div class="flex-1">
<form wire:submit.prevent="postComment" class="space-y-4">
<div>
<label for="comment" class="sr-only">Comment body</label>
<textarea id="comment" name="comment" rows="3"
class="peer block min-h-[auto] w-full border-1 bg-transparent px-3 py-[0.32rem] leading-[1.6] outline-none transition-all duration-200 ease-linear dark:placeholder:text-neutral-200 border-gray-300 dark:border-neutral-950 dark:bg-neutral-900 dark:text-gray-300 focus:border-rose-500 dark:focus:border-rose-600 focus:ring-rose-500 dark:focus:ring-rose-600 rounded-md shadow-sm
@error('newCommentState.body') border-red-500 @enderror"
placeholder="Write something" wire:model.defer="newCommentState.body"></textarea>
<label for="comment" class="sr-only">
Comment body
</label>
<textarea
id="comment"
rows="4"
wire:model.defer="newCommentState.body"
placeholder="Write a comment..."
class="w-full rounded-2xl border border-neutral-300 bg-white px-4 py-3 text-sm text-neutral-900 placeholder:text-neutral-400 shadow-sm transition focus:border-rose-500 focus:outline-none focus:ring-4 focus:ring-rose-500/10 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-100 dark:placeholder:text-neutral-500 dark:focus:border-rose-500 @error('newCommentState.body') border-red-500 @enderror"
></textarea>
@error('newCommentState.body')
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
<p class="mt-2 text-sm text-red-500">
{{ $message }}
</p>
@enderror
</div>
<div class="mt-3 flex items-center justify-between">
<button type="submit"
class="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-md shadow-sm text-white bg-rose-600 hover:bg-rose-700 focus:outline-none focus:ring-2 focus:ring-rose-500">
Comment
<div class="flex justify-end">
<button
type="submit"
class="inline-flex items-center rounded-xl bg-rose-600 px-5 py-2.5 text-sm font-medium text-white transition hover:bg-rose-700 focus:outline-none focus:ring-4 focus:ring-rose-500/30"
>
Post Comment
</button>
</div>
</form>
</div>
</div>
@endauth
@guest
<p class="text-gray-900 dark:text-gray-200">Log in to comment.</p>
<div class="rounded-xl border border-dashed border-neutral-300 p-6 text-center dark:border-neutral-700">
<p class="text-sm text-neutral-600 dark:text-neutral-400">
Log in to join the discussion.
</p>
</div>
@endguest
</div>
<!-- Comments -->
<div class="px-4 py-6 sm:px-6">
<div class="space-y-8">
{{-- Comments --}}
<div class="px-6 py-6">
@if ($comments->isNotEmpty())
<div class="space-y-6">
@foreach($comments as $comment)
<livewire:comment :comment="$comment" :key="$comment->id"/>
@endforeach
</div>
<div class="mt-8">
{{ $comments->links('pagination::tailwind') }}
</div>
@else
<p class="text-gray-900 dark:text-gray-200">No comments yet.</p>
<div class="rounded-2xl border border-dashed border-neutral-300 py-12 text-center dark:border-neutral-700">
<p class="text-neutral-500 dark:text-neutral-400">
No comments yet.
</p>
</div>
@endif
</div>
</div>
</div>
</div>
</section>