Skip to content

Commit

Permalink
refactor: increasing readability
Browse files Browse the repository at this point in the history
  • Loading branch information
yilanboy committed Nov 4, 2024
1 parent 01746ef commit c578bfb
Showing 1 changed file with 30 additions and 54 deletions.
84 changes: 30 additions & 54 deletions resources/views/livewire/shared/comments/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
</script>
@endscript

@php
use App\Enums\CommentOrder;
@endphp

<div
class="w-full"
id="comments"
Expand Down Expand Up @@ -75,9 +79,9 @@ class="absolute right-0 z-10 mt-2 w-32 origin-top-right rounded-md bg-gray-50 sh
@class([
'flex w-full justify-start px-4 py-2',
'bg-gray-200 text-gray-900 outline-none dark:bg-gray-600 dark:text-gray-50' =>
$order === App\Enums\CommentOrder::POPULAR,
$order === CommentOrder::POPULAR,
'text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700' =>
$order !== App\Enums\CommentOrder::POPULAR,
$order !== CommentOrder::POPULAR,
])
x-on:click="changeOrder"
>熱門留言</button>
Expand All @@ -87,9 +91,9 @@ class="absolute right-0 z-10 mt-2 w-32 origin-top-right rounded-md bg-gray-50 sh
@class([
'flex w-full justify-start px-4 py-2',
'bg-gray-200 text-gray-900 outline-none dark:bg-gray-600 dark:text-gray-50' =>
$order === App\Enums\CommentOrder::LATEST,
$order === CommentOrder::LATEST,
'text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700' =>
$order !== App\Enums\CommentOrder::LATEST,
$order !== CommentOrder::LATEST,
])
x-on:click="changeOrder"
>由新到舊</button>
Expand All @@ -99,9 +103,9 @@ class="absolute right-0 z-10 mt-2 w-32 origin-top-right rounded-md bg-gray-50 sh
@class([
'flex w-full justify-start px-4 py-2',
'bg-gray-200 text-gray-900 outline-none dark:bg-gray-600 dark:text-gray-50' =>
$order === App\Enums\CommentOrder::OLDEST,
$order === CommentOrder::OLDEST,
'text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700' =>
$order !== App\Enums\CommentOrder::OLDEST,
$order !== CommentOrder::OLDEST,
])
x-on:click="changeOrder"
>由舊到新</button>
Expand Down Expand Up @@ -129,55 +133,27 @@ class="group relative overflow-hidden rounded-xl bg-emerald-500 px-6 py-2 [trans
</div>
</div>

@if ($order === App\Enums\CommentOrder::LATEST)
{{-- new comment will show here --}}
<livewire:shared.comments.comment-group
:$maxLayer
:$postId
:$postAuthorId
{{-- if it's root comment, the comment group id is 'root-group' --}}
:comment-group-name="'root-new-comment-group'"
/>

{{-- comments list --}}
<livewire:shared.comments.comment-list
:$maxLayer
:$postId
:$postAuthorId
:order="App\Enums\CommentOrder::LATEST"
/>
@elseif ($order === App\Enums\CommentOrder::OLDEST)
{{-- new comment will show here --}}
<livewire:shared.comments.comment-group
:$maxLayer
:$postId
:$postAuthorId
{{-- if it's root comment, the comment group id is 'root-group' --}}
:comment-group-name="'root-new-comment-group'"
/>

{{-- comments list --}}
<livewire:shared.comments.comment-list
:$maxLayer
:$postId
:$postAuthorId
:order="App\Enums\CommentOrder::OLDEST"
/>
@else
<livewire:shared.comments.comment-group
:$maxLayer
:$postId
:$postAuthorId
:comment-group-name="'root-new-comment-group'"
/>
@foreach (CommentOrder::cases() as $case)
@if ($case === $order)
{{-- new root comment will show here --}}
<livewire:shared.comments.comment-group
:$maxLayer
:$postId
:$postAuthorId
:comment-group-name="'root-new-comment-group'"
:key="'root-new-comment-group-order-by-' . $order->value"
/>

<livewire:shared.comments.comment-list
:$maxLayer
:$postId
:$postAuthorId
:order="App\Enums\CommentOrder::POPULAR"
/>
@endif
{{-- root comment list --}}
<livewire:shared.comments.comment-list
:$maxLayer
:$postId
:$postAuthorId
:$order
:key="'root-comment-list-order-by-' . $order->value"
/>
@endif
@endforeach

{{-- create comment modal --}}
<livewire:shared.comments.create-comment-modal :$postId />
Expand Down

0 comments on commit c578bfb

Please sign in to comment.