Skip to content

Commit

Permalink
refactor: comment order dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
yilanboy committed Nov 12, 2024
1 parent d8e487b commit 7804d63
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 40 deletions.
11 changes: 10 additions & 1 deletion app/Enums/CommentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@

enum CommentOrder: string
{
case POPULAR = 'popular';

case LATEST = 'latest';

case OLDEST = 'oldest';

case POPULAR = 'popular';
public function label(): string
{
return match ($this) {
self::POPULAR => '熱門留言',
self::LATEST => '由新到舊',
self::OLDEST => '由舊到新',
};
}
}
6 changes: 3 additions & 3 deletions resources/views/livewire/pages/users/show-user-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class="relative z-20 inline-flex h-8 w-full cursor-pointer items-center justify-
x-on:click="tabButtonClicked($el)"
{{-- update url query parameter in livewire --}}
wire:click="changeTab('{{ $userInfoTab }}')"
wire:key="{{ $userInfoTab->value . '-tab-button' }}"
wire:key="{{ $userInfoTab->value }}-tab-button"
>
<x-dynamic-component
class="w-4"
Expand All @@ -79,12 +79,12 @@ class="absolute left-0 z-10 h-full w-1/2 duration-300 ease-out"
x-cloak
x-show="tabContentActive($el)"
x-transition:enter.duration.300ms
wire:key="{{ $userInfoTab->value . '-content' }}"
wire:key="{{ $userInfoTab->value }}-content"
>
<livewire:dynamic-component
:key="$userInfoTab->value . '-content'"
:is="$userInfoTab->livewireComponentName()"
:user-id="$user->id"
:key="$userInfoTab->value . '-content'"
/>
</div>
@endforeach
Expand Down
51 changes: 15 additions & 36 deletions resources/views/livewire/shared/comments/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,21 @@ class="absolute right-0 z-10 mt-2 w-32 origin-top-right rounded-md bg-gray-50 sh
x-on:click.outside="closeOrderDropdown"
>
<div class="w-full py-1">
<button
data-order="popular"
type="button"
@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 === CommentOrder::POPULAR,
'text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700' =>
$order !== CommentOrder::POPULAR,
])
x-on:click="changeOrder"
>熱門留言</button>
<button
data-order="latest"
type="button"
@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 === CommentOrder::LATEST,
'text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700' =>
$order !== CommentOrder::LATEST,
])
x-on:click="changeOrder"
>由新到舊</button>
<button
data-order="oldest"
type="button"
@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 === CommentOrder::OLDEST,
'text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700' =>
$order !== CommentOrder::OLDEST,
])
x-on:click="changeOrder"
>由舊到新</button>
@foreach (CommentOrder::cases() as $commentOrder)
<button
data-order="{{ $commentOrder->value }}"
type="button"
@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 === $commentOrder,
'text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700' =>
$order !== $commentOrder,
])
x-on:click="changeOrder"
wire:key="{{ $commentOrder->value }}-comment-order"
>{{ $commentOrder->label() }}</button>
@endforeach
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/shared/posts/posts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<button
type="button"
wire:click.prevent="changeOrder('{{ $postOrder }}')"
wire:key="{{ $postOrder->value }}-post-order"
@class([
'flex w-1/3 md:w-auto items-center px-4 py-2 transition duration-300 rounded-lg ',
'bg-gray-50 dark:bg-gray-800' => $order === $postOrder->value,
Expand Down

0 comments on commit 7804d63

Please sign in to comment.