mirror of
https://github.com/pelican-dev/panel.git
synced 2026-05-04 18:00:48 +03:00
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
class AlertBannerContainer extends Component
|
|
{
|
|
public AlertBannerCollection $alertBanners;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->alertBanners = new AlertBannerCollection();
|
|
|
|
foreach (session()->pull('alert-banners', []) as $alertBanner) {
|
|
// Alerts created during Livewire requests should have been consumed by the event handler on the same page.
|
|
if (!empty($alertBanner['from_livewire'])) {
|
|
// If they weren't, then discard them instead of showing on the wrong page.
|
|
continue;
|
|
}
|
|
|
|
$alertBanner = AlertBanner::fromArray($alertBanner);
|
|
$this->alertBanners->put($alertBanner->getId(), $alertBanner);
|
|
}
|
|
}
|
|
|
|
#[On('alertBannerSent')]
|
|
public function pullFromSession(): void
|
|
{
|
|
foreach (session()->pull('alert-banners', []) as $alertBanner) {
|
|
unset($alertBanner['from_livewire']);
|
|
$alertBanner = AlertBanner::fromArray($alertBanner);
|
|
$this->alertBanners->put($alertBanner->getId(), $alertBanner);
|
|
}
|
|
}
|
|
|
|
public function remove(string $id): void
|
|
{
|
|
if ($this->alertBanners->has($id)) {
|
|
$this->alertBanners->forget($id);
|
|
}
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.alerts.alert-banner-container');
|
|
}
|
|
}
|