Skip to content

Commit b97274b

Browse files
feat[lar-137] Change count and indicator livewire component to volt component
feat:[lar-137] Change count and indicator livewire component to volt component
1 parent d0be62b commit b97274b

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

resources/views/livewire/notification-count.blade.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
<?php
22
3-
use Livewire\Volt\Component;
4-
use Livewire\Attributes\On;
3+
declare(strict_types=1);
54
6-
new class extends Component {
5+
use function Livewire\Volt\{on};
6+
use Illuminate\Support\Facades\Auth;
77
8-
public function with(): array
9-
{
10-
return [
11-
'count' => \Illuminate\Support\Facades\Auth::user()->unreadNotifications()->count(),
12-
];
13-
}
8+
use function Livewire\Volt\{state};
149
15-
#[On('NotificationMarkedAsRead')]
16-
public function updateCount(int $count): int
17-
{
18-
return $count;
19-
}
20-
} ?>
10+
state(['count' => Auth::user()->unreadNotifications()->count()]);
11+
12+
on(['NotificationMarkedAsRead' => function (int $count) {
13+
return $count;
14+
}]);
15+
16+
?>
2117

2218
<span class="rounded-full bg-green-100 px-3 text-base text-green-500">
2319
{{ $count }}
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
<?php
22
3-
use Livewire\Volt\Component;
4-
use Livewire\Attributes\On;
3+
declare(strict_types=1);
4+
5+
use function Livewire\Volt\{on};
56
use Illuminate\Support\Facades\Auth;
67
7-
new class extends Component {
8+
use function Livewire\Volt\{state};
9+
10+
state(['hasNotification' => Auth::user()->unreadNotifications()->count() > 0 ]);
811
9-
public function with(): array
10-
{
11-
return [
12-
'hasNotification' => $this->setHasNotification(
13-
Auth::user()->unreadNotifications()->count(), // @phpstan-ignore-line
14-
),
15-
];
16-
}
12+
on(['NotificationMarkedAsRead' => function (int $count) {
13+
return $count > 0 ;
14+
}]);
1715
18-
#[On('NotificationMarkedAsRead')]
19-
public function setHasNotification(int $count): bool
20-
{
21-
return $count > 0;
22-
}
23-
} ?>
16+
?>
2417

2518
<span
26-
class="{{ $hasNotification ? 'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' : 'hidden' }}"
19+
@class([
20+
'hidden' => !$hasNotification,
21+
'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' => $hasNotification
22+
])
2723
></span>

0 commit comments

Comments
 (0)