-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alert banner improvements: auto-refresh, fixes & "closeable" (#924)
* fix websocket error always displaying * use livewire component with polling for alert banner container * add id to alert banner * cleanup blade file and add "closeable" property
- Loading branch information
Showing
9 changed files
with
134 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use Illuminate\Contracts\View\View; | ||
use Livewire\Component; | ||
|
||
class AlertBannerContainer extends Component | ||
{ | ||
public array $alertBanners; | ||
|
||
public function mount(): void | ||
{ | ||
$this->alertBanners = []; | ||
$this->pullFromSession(); | ||
} | ||
|
||
public function pullFromSession(): void | ||
{ | ||
foreach (session()->pull('alert-banners', []) as $alertBanner) { | ||
$alertBanner = AlertBanner::fromLivewire($alertBanner); | ||
$this->alertBanners[$alertBanner->getId()] = $alertBanner; | ||
} | ||
} | ||
|
||
public function remove(string $id): void | ||
{ | ||
unset($this->alertBanners[$id]); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.alerts.alert-banner-container'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
resources/views/filament/alerts/alert-banner-container.blade.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
resources/views/livewire/alerts/alert-banner-container.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div wire:poll.1s="pullFromSession" id="alert-banner-container" class="flex flex-col gap-4"> | ||
@foreach (array_values($alertBanners) as $alertBanner) | ||
@include('livewire.alerts.alert-banner', ['alertBanner' => $alertBanner]) | ||
@endforeach | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@props(['alertBanner']) | ||
|
||
@php | ||
$icon = $alertBanner->getIcon(); | ||
$title = $alertBanner->getTitle(); | ||
$body = $alertBanner->getBody(); | ||
@endphp | ||
|
||
<div class="{{$alertBanner->getColorClasses()}} flex p-4 mt-3 rounded-xl shadow-lg bg-white dark:bg-gray-900 ring-1 ring-gray-950/5 dark:ring-white/10"> | ||
@if (filled($icon)) | ||
<x-filament::icon :icon="$icon" class="h-8 w-8 mr-2" color="{{$alertBanner->getStatus()}}" /> | ||
@endif | ||
|
||
<div class="flex flex-col flex-grow"> | ||
@if (filled($title)) | ||
<p class="font-bold">{{str($title)->sanitizeHtml()->toHtmlString()}}</p> | ||
@endif | ||
|
||
@if (filled($body)) | ||
<p class="font-normal">{{str($body)->sanitizeHtml()->toHtmlString()}}</p> | ||
@endif | ||
</div> | ||
|
||
@if ($alertBanner->isCloseable()) | ||
<x-filament::icon-button color="gray" icon="tabler-x" wire:click="remove('{{$alertBanner->getID()}}')" /> | ||
@endif | ||
</div> |