Co-authored-by: jon brookes <marshyon@gmail.com> Reviewed-on: https://codeberg.org/headshed/share-lt/pulls/20
225 lines
12 KiB
PHP
225 lines
12 KiB
PHP
<?php
|
||
|
||
namespace App\Providers\Filament;
|
||
|
||
use Filament\Http\Middleware\Authenticate;
|
||
use Filament\Http\Middleware\AuthenticateSession;
|
||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||
use Filament\Pages\Dashboard;
|
||
use Filament\Panel;
|
||
use Filament\PanelProvider;
|
||
use Filament\Support\Colors\Color;
|
||
use Filament\Support\Facades\FilamentView;
|
||
use Filament\View\PanelsRenderHook;
|
||
use Filament\Widgets\AccountWidget;
|
||
use Filament\Widgets\FilamentInfoWidget;
|
||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||
use Illuminate\Session\Middleware\StartSession;
|
||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||
|
||
class AdminPanelProvider extends PanelProvider
|
||
{
|
||
public function panel(Panel $panel): Panel
|
||
{
|
||
return $panel
|
||
->default()
|
||
->sidebarCollapsibleOnDesktop()
|
||
->id('admin')
|
||
->path('admin')
|
||
->login()
|
||
->colors([
|
||
'primary' => Color::Blue,
|
||
])
|
||
->resources([
|
||
\App\Filament\Resources\Entries\EntryResource::class,
|
||
\App\Filament\Resources\Media\MediaResource::class,
|
||
\App\Filament\Resources\Categroys\CategroyResource::class,
|
||
])
|
||
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
|
||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
|
||
->pages([
|
||
Dashboard::class,
|
||
])
|
||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
|
||
->widgets([
|
||
AccountWidget::class,
|
||
FilamentInfoWidget::class,
|
||
])
|
||
->middleware([
|
||
EncryptCookies::class,
|
||
AddQueuedCookiesToResponse::class,
|
||
StartSession::class,
|
||
AuthenticateSession::class,
|
||
ShareErrorsFromSession::class,
|
||
VerifyCsrfToken::class,
|
||
SubstituteBindings::class,
|
||
DisableBladeIconComponents::class,
|
||
DispatchServingFilamentEvent::class,
|
||
])
|
||
->authMiddleware([
|
||
Authenticate::class,
|
||
]);
|
||
}
|
||
|
||
public function boot(): void
|
||
{
|
||
FilamentView::registerRenderHook(
|
||
PanelsRenderHook::BODY_END,
|
||
fn(): string => \Illuminate\Support\Facades\Blade::render('@vite("resources/js/app.js")'),
|
||
);
|
||
|
||
FilamentView::registerRenderHook(
|
||
PanelsRenderHook::BODY_END,
|
||
function (): string {
|
||
return '
|
||
<script>
|
||
document.addEventListener("DOMContentLoaded", function() {
|
||
if (window.Echo) {
|
||
<<<<<<< HEAD
|
||
|
||
=======
|
||
>>>>>>> 4143902e603c7e3e25de5e5f49c1116dd5a5743b
|
||
console.log("Setting up Filament Reverb notifications...");
|
||
console.log("Available globals:", {
|
||
FilamentNotification: typeof FilamentNotification,
|
||
Livewire: typeof window.Livewire,
|
||
filament: typeof window.filament
|
||
});
|
||
|
||
<<<<<<< HEAD
|
||
|
||
=======
|
||
>>>>>>> 4143902e603c7e3e25de5e5f49c1116dd5a5743b
|
||
// Listen for preview site built events
|
||
window.Echo.channel("filament-notifications")
|
||
.listen("preview-site.built", function(event) {
|
||
console.log("🎉 Received preview site built event:", event);
|
||
|
||
// Use Filament v4 notification system
|
||
if (typeof FilamentNotification !== "undefined") {
|
||
new FilamentNotification()
|
||
.title(event.message)
|
||
.success()
|
||
.duration(5000)
|
||
.send();
|
||
console.log("✅ Sent via FilamentNotification v4");
|
||
} else {
|
||
console.warn("FilamentNotification not available");
|
||
// Fallback notification
|
||
const notification = document.createElement("div");
|
||
notification.style.cssText = `
|
||
position: fixed !important;
|
||
top: 20px !important;
|
||
right: 20px !important;
|
||
z-index: 999999 !important;
|
||
background: #10b981 !important;
|
||
color: white !important;
|
||
padding: 16px 20px !important;
|
||
border-radius: 8px !important;
|
||
box-shadow: 0 10px 25px rgba(0,0,0,0.3) !important;
|
||
font-family: system-ui, -apple-system, sans-serif !important;
|
||
font-size: 14px !important;
|
||
font-weight: 500 !important;
|
||
max-width: 350px !important;
|
||
display: block !important;
|
||
opacity: 1 !important;
|
||
`;
|
||
|
||
notification.innerHTML = `
|
||
<div style="display: flex; align-items: center; justify-content: space-between;">
|
||
<div style="margin-right: 15px;">
|
||
✓ ${event.message}
|
||
</div>
|
||
<button onclick="this.parentElement.parentElement.remove()"
|
||
style="background: none; border: none; color: white; font-size: 18px; cursor: pointer; padding: 0;">
|
||
×
|
||
</button>
|
||
</div>
|
||
`;
|
||
|
||
document.body.appendChild(notification);
|
||
console.log("✅ Created fallback notification");
|
||
|
||
// Auto-remove after 5 seconds
|
||
setTimeout(() => {
|
||
if (notification.parentNode) {
|
||
notification.remove();
|
||
}
|
||
}, 5000);
|
||
}
|
||
})
|
||
.listen(".preview-site.built", function(event) {
|
||
console.log("🔄 Also listening with dot prefix (the working one):", event);
|
||
<<<<<<< HEAD
|
||
console.log("message:", event.message);
|
||
=======
|
||
>>>>>>> 4143902e603c7e3e25de5e5f49c1116dd5a5743b
|
||
|
||
// Use Filament v4 notification system
|
||
if (typeof FilamentNotification !== "undefined") {
|
||
new FilamentNotification()
|
||
.title(event.message)
|
||
.success()
|
||
.duration(5000)
|
||
.send();
|
||
console.log("✅ Sent via FilamentNotification v4 (from dot prefix)");
|
||
} else {
|
||
console.warn("FilamentNotification not available, creating fallback");
|
||
// Fallback notification
|
||
const notification = document.createElement("div");
|
||
notification.style.cssText = `
|
||
position: fixed !important;
|
||
top: 20px !important;
|
||
right: 20px !important;
|
||
z-index: 999999 !important;
|
||
background: #3b82f6 !important;
|
||
color: white !important;
|
||
padding: 16px 20px !important;
|
||
border-radius: 8px !important;
|
||
box-shadow: 0 10px 25px rgba(0,0,0,0.3) !important;
|
||
font-family: system-ui, -apple-system, sans-serif !important;
|
||
font-size: 14px !important;
|
||
font-weight: 500 !important;
|
||
max-width: 350px !important;
|
||
display: block !important;
|
||
opacity: 1 !important;
|
||
`;
|
||
|
||
notification.innerHTML = `
|
||
<div style="display: flex; align-items: center; justify-content: space-between;">
|
||
<div style="margin-right: 15px;">
|
||
🔄 ${event.message}
|
||
</div>
|
||
<button onclick="this.parentElement.parentElement.remove()"
|
||
style="background: none; border: none; color: white; font-size: 18px; cursor: pointer; padding: 0;">
|
||
×
|
||
</button>
|
||
</div>
|
||
`;
|
||
|
||
document.body.appendChild(notification);
|
||
console.log("✅ Created dot prefix fallback notification");
|
||
|
||
// Auto-remove after 5 seconds
|
||
setTimeout(() => {
|
||
if (notification.parentNode) {
|
||
notification.remove();
|
||
}
|
||
}, 5000);
|
||
}
|
||
});
|
||
|
||
console.log("✅ Event listeners set up for filament-notifications channel");
|
||
} else {
|
||
console.error("❌ Echo is not available for Filament notifications");
|
||
}
|
||
});
|
||
</script>';
|
||
}
|
||
);
|
||
}
|
||
}
|