Skip to content

Commit

Permalink
add id to alert banner
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 committed Jan 17, 2025
1 parent a22abb7 commit f3cb04b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions app/Livewire/AlertBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@
use Filament\Notifications\Concerns;
use Filament\Support\Concerns\EvaluatesClosures;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Str;

final class AlertBanner implements Arrayable
{
use Concerns\HasBody;
use Concerns\HasIcon;
use Concerns\HasId;
use Concerns\HasStatus;
use Concerns\HasTitle;
use EvaluatesClosures;

public static function make(): static
public static function make(?string $id = null): static
{
return new self();
$static = new self();
$static->id($id ?? Str::orderedUuid());

return $static;
}

public function toArray(): array
{
return [
'id' => $this->getId(),
'title' => $this->getTitle(),
'body' => $this->getBody(),
'status' => $this->getStatus(),
Expand All @@ -33,6 +39,7 @@ public static function fromArray(array $data): static
{
$static = static::make();

$static->id($data['id']);
$static->title($data['title']);
$static->body($data['body']);
$static->status($data['status']);
Expand Down
9 changes: 8 additions & 1 deletion app/Livewire/AlertBannerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public function mount(): void

public function pullFromSession(): void
{
$this->alertBanners = array_merge($this->alertBanners, session()->pull('alert-banners', []));
foreach (session()->pull('alert-banners', []) as $alertBanner) {
$this->alertBanners[$alertBanner['id']] = $alertBanner;
}
}

public function remove(string $id): void
{
unset($this->alertBanners[$id]);
}

public function render(): View
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div wire:poll.1s="pullFromSession" id="alert-banner-container" class="flex flex-col gap-4">
@foreach ($alertBanners as $alertBanner)
@foreach (array_values($alertBanners) as $alertBanner)
@include('livewire.alerts.alert-banner', ['alertBanner' => $alertBanner])
@endforeach
</div>

0 comments on commit f3cb04b

Please sign in to comment.