Skip to content

Commit 82fcb62

Browse files
lar:[137] change notification count and indicator to volt component (#257)
1 parent 2c23bc0 commit 82fcb62

File tree

6 files changed

+73
-68
lines changed

6 files changed

+73
-68
lines changed

app/Livewire/NotificationCount.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

app/Livewire/NotificationIndicator.php

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Support\Facades\Auth;
6+
7+
use function Livewire\Volt\{on};
8+
use function Livewire\Volt\{state};
9+
10+
state(['count' => Auth::user()->unreadNotifications()->count()]);
11+
12+
on(['NotificationMarkedAsRead' => fn (int $count) => $count ]);
13+
14+
?>
15+
116
<span class="rounded-full bg-green-100 px-3 text-base text-green-500">
217
{{ $count }}
318
</span>
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Support\Facades\Auth;
6+
7+
use function Livewire\Volt\{on};
8+
use function Livewire\Volt\{state};
9+
10+
state(['hasNotification' => Auth::user()->unreadNotifications()->count() > 0 ]);
11+
12+
on(['NotificationMarkedAsRead' => fn (int $count) => $count > 0 ]);
13+
14+
?>
15+
116
<span
2-
class="{{ $hasNotification ? 'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' : 'hidden' }}"
17+
@class([
18+
'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white',
19+
'hidden' => ! $hasNotification,
20+
'block' => $hasNotification,
21+
])
322
></span>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Livewire\Volt\Volt;
6+
7+
beforeEach(function (): void {
8+
$this->user = $this->login();
9+
});
10+
11+
it('renders successfully', function (): void {
12+
Volt::test('notification-count')
13+
->assertStatus(200);
14+
});
15+
16+
it('can display user count notification', function (): void {
17+
Volt::test('notification-count')
18+
->assertSee($this->user->unreadNotifications()->count());
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Livewire\Volt\Volt;
6+
7+
beforeEach(function (): void {
8+
$this->user = $this->login();
9+
});
10+
11+
it('renders successfully', function (): void {
12+
Volt::test('notification-indicator')
13+
->assertStatus(200);
14+
});
15+
16+
it('mask indicator if user can have unread notification', function (): void {
17+
Volt::test('notification-indicator')
18+
->assertSet('hasNotification', false);
19+
});

0 commit comments

Comments
 (0)