Skip to content

lar:[137] change notification count and indicator to volt component #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions app/Livewire/NotificationCount.php

This file was deleted.

32 changes: 0 additions & 32 deletions app/Livewire/NotificationIndicator.php

This file was deleted.

15 changes: 15 additions & 0 deletions resources/views/livewire/notification-count.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Auth;

use function Livewire\Volt\{on};
use function Livewire\Volt\{state};

state(['count' => Auth::user()->unreadNotifications()->count()]);

on(['NotificationMarkedAsRead' => fn (int $count) => $count ]);

?>

<span class="rounded-full bg-green-100 px-3 text-base text-green-500">
{{ $count }}
</span>
21 changes: 20 additions & 1 deletion resources/views/livewire/notification-indicator.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Auth;

use function Livewire\Volt\{on};
use function Livewire\Volt\{state};

state(['hasNotification' => Auth::user()->unreadNotifications()->count() > 0 ]);

on(['NotificationMarkedAsRead' => fn (int $count) => $count > 0 ]);

?>

<span
class="{{ $hasNotification ? 'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' : 'hidden' }}"
@class([
'shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white',
'hidden' => ! $hasNotification,
'block' => $hasNotification,
])
></span>
19 changes: 19 additions & 0 deletions tests/Feature/Livewire/Components/NotificationCountTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Livewire\Volt\Volt;

beforeEach(function (): void {
$this->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());
});
19 changes: 19 additions & 0 deletions tests/Feature/Livewire/Components/NotificationIndicatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Livewire\Volt\Volt;

beforeEach(function (): void {
$this->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);
});
Loading