From 4410e4c28c6e42670d095f2bd3bd8082784c995e Mon Sep 17 00:00:00 2001 From: Chri$ Date: Thu, 19 Dec 2024 03:02:21 +0100 Subject: [PATCH 1/3] lar:[137] change notification count and indicator to volt component feat[lar-137] Change count and indicator livewire component to volt component feat:[lar-137] Change count and indicator livewire component to volt component --- app/Livewire/NotificationCount.php | 35 ------------------- app/Livewire/NotificationIndicator.php | 32 ----------------- .../livewire/notification-count.blade.php | 17 +++++++++ .../livewire/notification-indicator.blade.php | 22 +++++++++++- .../Components/NotificationCountTest.php | 19 ++++++++++ .../Components/NotificationIndicatorTest.php | 19 ++++++++++ 6 files changed, 76 insertions(+), 68 deletions(-) delete mode 100644 app/Livewire/NotificationCount.php delete mode 100644 app/Livewire/NotificationIndicator.php create mode 100644 tests/Feature/Livewire/Components/NotificationCountTest.php create mode 100644 tests/Feature/Livewire/Components/NotificationIndicatorTest.php diff --git a/app/Livewire/NotificationCount.php b/app/Livewire/NotificationCount.php deleted file mode 100644 index 3eefbac5..00000000 --- a/app/Livewire/NotificationCount.php +++ /dev/null @@ -1,35 +0,0 @@ - 'updateCount', - ]; - - public function updateCount(int $count): int - { - return $count; - } - - public function render(): View - { - $this->count = Auth::user()->unreadNotifications()->count(); // @phpstan-ignore-line - - return view('livewire.notification-count', [ - 'count' => $this->count, - ]); - } -} diff --git a/app/Livewire/NotificationIndicator.php b/app/Livewire/NotificationIndicator.php deleted file mode 100644 index d7baa23b..00000000 --- a/app/Livewire/NotificationIndicator.php +++ /dev/null @@ -1,32 +0,0 @@ - 0; - } - - public function render(): View - { - $this->hasNotification = $this->setHasNotification( - Auth::user()->unreadNotifications()->count(), // @phpstan-ignore-line - ); - - return view('livewire.notification-indicator', [ - 'hasNotification' => $this->hasNotification, - ]); - } -} diff --git a/resources/views/livewire/notification-count.blade.php b/resources/views/livewire/notification-count.blade.php index 7e6ca155..b685a13f 100644 --- a/resources/views/livewire/notification-count.blade.php +++ b/resources/views/livewire/notification-count.blade.php @@ -1,3 +1,20 @@ + Auth::user()->unreadNotifications()->count()]); + +on(['NotificationMarkedAsRead' => function (int $count) { + return $count; +}]); + +?> + {{ $count }} diff --git a/resources/views/livewire/notification-indicator.blade.php b/resources/views/livewire/notification-indicator.blade.php index 5591ac6b..aff63cfb 100644 --- a/resources/views/livewire/notification-indicator.blade.php +++ b/resources/views/livewire/notification-indicator.blade.php @@ -1,3 +1,23 @@ + Auth::user()->unreadNotifications()->count() > 0 ]); + +on(['NotificationMarkedAsRead' => function (int $count) { + return $count > 0 ; +}]); + +?> + !$hasNotification, + 'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' => $hasNotification + ]) > diff --git a/tests/Feature/Livewire/Components/NotificationCountTest.php b/tests/Feature/Livewire/Components/NotificationCountTest.php new file mode 100644 index 00000000..8179bf18 --- /dev/null +++ b/tests/Feature/Livewire/Components/NotificationCountTest.php @@ -0,0 +1,19 @@ +user = $this->login(); +}); + +it('renders successfully', function (): void { + Volt::test('notification-count') + ->assertStatus(200); +}); + +it('can display user count notification', function (): void { + Volt::test('notification-count') + ->assertSee($this->user->unreadNotifications()->count()); +}); diff --git a/tests/Feature/Livewire/Components/NotificationIndicatorTest.php b/tests/Feature/Livewire/Components/NotificationIndicatorTest.php new file mode 100644 index 00000000..0791a500 --- /dev/null +++ b/tests/Feature/Livewire/Components/NotificationIndicatorTest.php @@ -0,0 +1,19 @@ +user = $this->login(); +}); + +it('renders successfully', function (): void { + Volt::test('notification-indicator') + ->assertStatus(200); +}); + +it('mask indicator if user can have unread notification', function (): void { + Volt::test('notification-indicator') + ->assertSet('hasNotification', false); +}); From bad57d803b881f08b665f02c61fe6438f8b95345 Mon Sep 17 00:00:00 2001 From: Chri$ Date: Thu, 19 Dec 2024 13:38:35 +0100 Subject: [PATCH 2/3] feat:[lar-137] change count and indicator component to volt component --- resources/views/livewire/notification-count.blade.php | 6 ++---- resources/views/livewire/notification-indicator.blade.php | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/resources/views/livewire/notification-count.blade.php b/resources/views/livewire/notification-count.blade.php index b685a13f..096b504c 100644 --- a/resources/views/livewire/notification-count.blade.php +++ b/resources/views/livewire/notification-count.blade.php @@ -2,16 +2,14 @@ declare(strict_types=1); -use function Livewire\Volt\{on}; use Illuminate\Support\Facades\Auth; +use function Livewire\Volt\{on}; use function Livewire\Volt\{state}; state(['count' => Auth::user()->unreadNotifications()->count()]); -on(['NotificationMarkedAsRead' => function (int $count) { - return $count; -}]); +on(['NotificationMarkedAsRead' => fn (int $count) => $count ); ?> diff --git a/resources/views/livewire/notification-indicator.blade.php b/resources/views/livewire/notification-indicator.blade.php index aff63cfb..16146878 100644 --- a/resources/views/livewire/notification-indicator.blade.php +++ b/resources/views/livewire/notification-indicator.blade.php @@ -2,16 +2,14 @@ declare(strict_types=1); -use function Livewire\Volt\{on}; use Illuminate\Support\Facades\Auth; +use function Livewire\Volt\{on}; use function Livewire\Volt\{state}; state(['hasNotification' => Auth::user()->unreadNotifications()->count() > 0 ]); -on(['NotificationMarkedAsRead' => function (int $count) { - return $count > 0 ; -}]); +on(['NotificationMarkedAsRead' => fn (int $count) => $count > 0]); ?> From d87e2eeafe3befc3f84ffa4de4373e1dc16c8a82 Mon Sep 17 00:00:00 2001 From: Chri$ Date: Thu, 19 Dec 2024 13:57:37 +0100 Subject: [PATCH 3/3] feat:[lar-137] Change indicator and count component to volt component feat:[lar-137] Change indicator and count livewire component to volt component --- resources/views/livewire/notification-count.blade.php | 2 +- resources/views/livewire/notification-indicator.blade.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/views/livewire/notification-count.blade.php b/resources/views/livewire/notification-count.blade.php index 096b504c..4c160d61 100644 --- a/resources/views/livewire/notification-count.blade.php +++ b/resources/views/livewire/notification-count.blade.php @@ -9,7 +9,7 @@ state(['count' => Auth::user()->unreadNotifications()->count()]); -on(['NotificationMarkedAsRead' => fn (int $count) => $count ); +on(['NotificationMarkedAsRead' => fn (int $count) => $count ]); ?> diff --git a/resources/views/livewire/notification-indicator.blade.php b/resources/views/livewire/notification-indicator.blade.php index 16146878..65416902 100644 --- a/resources/views/livewire/notification-indicator.blade.php +++ b/resources/views/livewire/notification-indicator.blade.php @@ -9,13 +9,14 @@ state(['hasNotification' => Auth::user()->unreadNotifications()->count() > 0 ]); -on(['NotificationMarkedAsRead' => fn (int $count) => $count > 0]); +on(['NotificationMarkedAsRead' => fn (int $count) => $count > 0 ]); ?> !$hasNotification, - 'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' => $hasNotification + 'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white', + 'hidden' => ! $hasNotification, + 'block' => $hasNotification, ]) >