Skip to content

Commit d0be62b

Browse files
lar:[137] change notification count and indicator to volt component
1 parent 38766e1 commit d0be62b

File tree

6 files changed

+83
-67
lines changed

6 files changed

+83
-67
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<?php
2+
3+
use Livewire\Volt\Component;
4+
use Livewire\Attributes\On;
5+
6+
new class extends Component {
7+
8+
public function with(): array
9+
{
10+
return [
11+
'count' => \Illuminate\Support\Facades\Auth::user()->unreadNotifications()->count(),
12+
];
13+
}
14+
15+
#[On('NotificationMarkedAsRead')]
16+
public function updateCount(int $count): int
17+
{
18+
return $count;
19+
}
20+
} ?>
21+
122
<span class="rounded-full bg-green-100 px-3 text-base text-green-500">
223
{{ $count }}
324
</span>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
<?php
2+
3+
use Livewire\Volt\Component;
4+
use Livewire\Attributes\On;
5+
use Illuminate\Support\Facades\Auth;
6+
7+
new class extends Component {
8+
9+
public function with(): array
10+
{
11+
return [
12+
'hasNotification' => $this->setHasNotification(
13+
Auth::user()->unreadNotifications()->count(), // @phpstan-ignore-line
14+
),
15+
];
16+
}
17+
18+
#[On('NotificationMarkedAsRead')]
19+
public function setHasNotification(int $count): bool
20+
{
21+
return $count > 0;
22+
}
23+
} ?>
24+
125
<span
226
class="{{ $hasNotification ? 'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' : 'hidden' }}"
327
></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)