diff --git a/hifi-src/index.html b/hifi-src/index.html index 534e126..615452d 100644 --- a/hifi-src/index.html +++ b/hifi-src/index.html @@ -15,9 +15,16 @@ - + + + + + + - diff --git a/hifi-src/public/og-image.jpg b/hifi-src/public/og-image.jpg new file mode 100644 index 0000000..7e02bbc Binary files /dev/null and b/hifi-src/public/og-image.jpg differ diff --git a/hifi-src/src/App.jsx b/hifi-src/src/App.jsx index a3cf939..912bd89 100644 --- a/hifi-src/src/App.jsx +++ b/hifi-src/src/App.jsx @@ -1,5 +1,6 @@ import { lazy, Suspense } from 'react'; import { Routes, Route, Navigate, useParams } from 'react-router-dom'; +import { MotionConfig } from 'framer-motion'; import ScrollToTop from './components/ScrollToTop.jsx'; import CustomCursor from './components/CustomCursor.jsx'; import SetupGate from './components/SetupGate.jsx'; @@ -12,17 +13,12 @@ import Home from './pages/public/Home.jsx'; import VehicleSelect from './pages/public/VehicleSelect.jsx'; import BrandPage from './pages/public/BrandPage.jsx'; import ModelPage from './pages/public/ModelPage.jsx'; -import GalleryOverview from './pages/public/GalleryOverview.jsx'; -import GalleryBrandPage from './pages/public/GalleryBrandPage.jsx'; -import GalleryProjectPage from './pages/public/GalleryProjectPage.jsx'; import Leistungen from './pages/public/Leistungen.jsx'; import ContactPage from './pages/public/ContactPage.jsx'; -import DownloadsPage from './pages/public/DownloadsPage.jsx'; -import Impressum from './pages/public/Impressum.jsx'; -import Datenschutz from './pages/public/Datenschutz.jsx'; -import AGB from './pages/public/AGB.jsx'; +import NotFound from './pages/public/NotFound.jsx'; -// Oeffentliche Seiten bleiben im Haupt-Bundle (sofort da beim Navigieren). Admin-Bereich, +// Die Kernseiten des Kaufwegs bleiben im Haupt-Bundle (sofort da beim Navigieren). Galerie, +// Downloads, Rechtstexte und die 404-Seite werden erst bei Aufruf nachgeladen. Admin-Bereich, // Login und Einrichtungs-Assistent werden erst geladen, wenn man sie aufruft - vorher lud // jeder Besucher den kompletten Admin-Code (Editor, Bildzuschnitt, QR-Codes, ...) mit. // @@ -56,6 +52,13 @@ const lazyPage = (load) => ) ); +const GalleryOverview = lazyPage(() => import('./pages/public/GalleryOverview.jsx')); +const GalleryBrandPage = lazyPage(() => import('./pages/public/GalleryBrandPage.jsx')); +const GalleryProjectPage = lazyPage(() => import('./pages/public/GalleryProjectPage.jsx')); +const DownloadsPage = lazyPage(() => import('./pages/public/DownloadsPage.jsx')); +const Impressum = lazyPage(() => import('./pages/public/Impressum.jsx')); +const Datenschutz = lazyPage(() => import('./pages/public/Datenschutz.jsx')); +const AGB = lazyPage(() => import('./pages/public/AGB.jsx')); const SetupWizard = lazyPage(() => import('./pages/public/SetupWizard.jsx')); const Login = lazyPage(() => import('./pages/admin/Login.jsx')); const Dashboard = lazyPage(() => import('./pages/admin/Dashboard.jsx')); @@ -95,7 +98,9 @@ function LegacyPackageRedirect() { export default function App() { return ( - <> + // reducedMotion="user": wer im Betriebssystem "Bewegung reduzieren" eingestellt hat, + // bekommt alle framer-motion-Animationen (Einblenden, Parallax, ...) ohne Bewegung. + @@ -119,6 +124,7 @@ export default function App() { } /> } /> } /> + } /> } /> @@ -144,26 +150,30 @@ export default function App() { } /> } + element={} > - } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + {/* Alte Adresse vor der Aufteilung in Firmendaten/Aussehen/Google-Dienste. */} + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> } /> - } /> + } /> - + ); } diff --git a/hifi-src/src/api/client.js b/hifi-src/src/api/client.js index a2e9edb..a701abf 100644 --- a/hifi-src/src/api/client.js +++ b/hifi-src/src/api/client.js @@ -16,6 +16,14 @@ export const subscribePendingRequests = (listener) => { return () => pendingListeners.delete(listener); }; +// Meldet abgelaufene Admin-Sitzungen (401), damit AdminLayout ein Login-Fenster ueber der +// aktuellen Seite oeffnen kann - ungespeicherte Eingaben bleiben so erhalten. +const unauthorizedListeners = new Set(); +export const subscribeUnauthorized = (listener) => { + unauthorizedListeners.add(listener); + return () => unauthorizedListeners.delete(listener); +}; + async function request(path, options = {}) { setPending(1); try { @@ -47,10 +55,20 @@ async function send(path, options) { } if (!res.ok) { - throw new Error(data?.error || `Fehler ${res.status}`); + // status/code erlauben dem Aufrufer eigene (uebersetzte) Meldungen statt des Servertexts. + const error = new Error(data?.error || `Fehler ${res.status}`); + error.status = res.status; + error.code = data?.code || null; + if (res.status === 401 && !path.startsWith('/auth/')) { + unauthorizedListeners.forEach((listener) => listener()); + } + throw error; } if (data === null && rawText) { - throw new Error('Unerwartete Server-Antwort (kein gültiges JSON)'); + const error = new Error('Unerwartete Server-Antwort (kein gültiges JSON)'); + error.status = res.status; + error.code = 'invalid_response'; + throw error; } return data; diff --git a/hifi-src/src/assets/videos/youtube-hintergrund-mobil.mp4 b/hifi-src/src/assets/videos/youtube-hintergrund-mobil.mp4 new file mode 100644 index 0000000..1f597b6 Binary files /dev/null and b/hifi-src/src/assets/videos/youtube-hintergrund-mobil.mp4 differ diff --git a/hifi-src/src/components/AdminLayout.jsx b/hifi-src/src/components/AdminLayout.jsx index 22e5706..f732d75 100644 --- a/hifi-src/src/components/AdminLayout.jsx +++ b/hifi-src/src/components/AdminLayout.jsx @@ -1,7 +1,10 @@ -import { Suspense, useEffect, useState } from 'react'; +import { Suspense, useCallback, useEffect, useState } from 'react'; import { Link, NavLink, Outlet, useNavigate } from 'react-router-dom'; import { useAuth } from '../context/AuthContext.jsx'; +import { AdminUiProvider } from '../context/AdminUiContext.jsx'; +import SessionGuard from './admin/SessionGuard.jsx'; import { api } from '../api/client.js'; +import { SITE_AREAS } from '../utils/siteAreas.js'; import ThemeToggle from './ThemeToggle.jsx'; import { CustomFontsProvider } from '../context/CustomFontsContext.jsx'; import CustomFontFaces from './CustomFontFaces.jsx'; @@ -22,6 +25,19 @@ const ICONS = { image: 'M4 5h16a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1Zm2 12 4.5-5.5L14 16l2.5-3L20 17H6ZM8 9.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z', help: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-5.5v.01M9.5 9.25a2.5 2.5 0 1 1 3.5 2.29c-.7.32-1 .77-1 1.46v.3', download: 'M12 4v11m0 0-4-4m4 4 4-4M5 19h14', + gauge: 'M4 13a8 8 0 1 1 16 0M12 13l3.5-3.5M6 17h12', + inbox: 'M3 13h5l1.5 2.5h5L16 13h5M5 5h14l2 8v5a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-5l2-8Z', + building: 'M4 21V5a1 1 0 0 1 1-1h9a1 1 0 0 1 1 1v16M15 9h4a1 1 0 0 1 1 1v11M3 21h18M8 8h3M8 12h3M8 16h3', + palette: 'M12 3a9 9 0 1 0 0 18c1 0 1.5-.7 1.5-1.5 0-.4-.2-.8-.4-1.1-.3-.3-.4-.7-.4-1.1 0-.8.7-1.5 1.5-1.5H16a5 5 0 0 0 5-5c0-4.4-4-7.8-9-7.8ZM7.5 12h.01M10 7.5h.01M15 7.5h.01', + file: 'M7 3h7l5 5v12a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Zm7 0v5h5M9 13h6M9 17h6', + wrench: 'M14.5 6.5a4 4 0 0 0-5.3 5.3L4 17l3 3 5.2-5.2a4 4 0 0 0 5.3-5.3l-2.5 2.5-2.5-.5-.5-2.5 2.5-2.5Z', + server: 'M4 4h16v6H4V4Zm0 10h16v6H4v-6Zm3-7h.01M7 17h.01', + globe: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm-9-9h18M12 3c2.5 2.5 3.5 5.5 3.5 9s-1 6.5-3.5 9c-2.5-2.5-3.5-5.5-3.5-9s1-6.5 3.5-9Z', + send: 'M4 12 20 4l-4 16-4-7-8-1Zm8 1 8-9', + refresh: 'M20 11a8 8 0 0 0-14.9-3M4 4v4h4m-4 5a8 8 0 0 0 14.9 3M20 20v-4h-4', + trash: 'M5 7h14M10 11v6m4-6v6M6 7l1 13h10l1-13M9 7V4h6v3', + external: 'M14 4h6v6m0-6-9 9M19 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h5', + pause: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm-2-12v6m4-6v6', }; const Icon = ({ path }) => ( @@ -36,64 +52,97 @@ export default function AdminLayout() { const [mobileOpen, setMobileOpen] = useState(false); const [newContactCount, setNewContactCount] = useState(0); const [customFonts, setCustomFonts] = useState([]); + // Fuer die Warnleiste oben: ausgeblendete Website-Bereiche und aktiver Wartungsmodus sollen + // nie unbemerkt bleiben. + const [hiddenAreas, setHiddenAreas] = useState([]); + const [maintenanceOn, setMaintenanceOn] = useState(false); + + // Wird auch von Seiten aufgerufen (useAdminUi().refreshCounters), z. B. nachdem eine Anfrage + // auf "Erledigt" gesetzt oder ein Bereich ausgeblendet wurde - frueher blieb das Badge bis + // zum Neuladen falsch. + const refreshCounters = useCallback(() => { + if (hasPermission('contact.manage')) { + api.get('/contact').then((rows) => setNewContactCount(rows.filter((r) => r.status === 'new').length)).catch(() => {}); + } + api.get('/site-settings').then((res) => setHiddenAreas(res.hidden_areas || [])).catch(() => {}); + api.get('/maintenance').then((res) => setMaintenanceOn(!!res?.global?.enabled)).catch(() => {}); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [user?.id]); useEffect(() => { - if (!hasPermission('contact.manage')) return; - api.get('/contact').then((rows) => setNewContactCount(rows.filter((r) => r.status === 'new').length)).catch(() => {}); - }, []); + refreshCounters(); + const timer = setInterval(refreshCounters, 2 * 60 * 1000); + return () => clearInterval(timer); + }, [refreshCounters]); + + const hiddenAreaLabels = SITE_AREAS.filter((a) => hiddenAreas.includes(a.key)).map((a) => a.label); const loadCustomFonts = () => api.get('/custom-fonts').then(setCustomFonts).catch(() => {}); useEffect(() => { loadCustomFonts(); }, []); + // Aufgebaut nach Aufgaben statt nach Technik: oben das Tagesgeschaeft, ganz unten der + // Bereich "System" mit allem, was man im Alltag nicht braucht (und besser nicht anfasst). const navGroups = [ { title: null, links: [ - { to: '/admin', label: 'Dashboard', icon: 'home', end: true }, - { to: '/admin/account', label: 'Mein Konto', icon: 'lock' }, + { to: '/admin', label: 'Übersicht', icon: 'gauge', end: true }, + { to: '/admin/contact-requests', label: 'Anfragen', icon: 'inbox', permission: 'contact.manage', badge: newContactCount }, ], }, { - title: 'Fahrzeug-Katalog', + title: 'Fahrzeuge & Pakete', links: [ - { to: '/admin/brands', label: 'Marken', icon: 'tag', permission: 'brands.manage' }, + { to: '/admin/brands', label: 'Fahrzeugmarken', icon: 'tag', permission: 'brands.manage' }, { to: '/admin/models', label: 'Modelle', icon: 'car', permission: 'models.manage' }, { to: '/admin/packages', label: 'Pakete', icon: 'box', permission: 'packages.manage' }, ], }, { - title: 'Website', + title: 'Website-Inhalte', links: [ { to: '/admin/home-sections', label: 'Startseite', icon: 'home', permission: 'content.manage' }, { to: '/admin/services', label: 'Leistungen', icon: 'briefcase', permission: 'services.manage' }, { to: '/admin/faqs', label: 'FAQ', icon: 'help', permission: 'content.manage' }, - { to: '/admin/partners', label: 'Partner', icon: 'tag', permission: 'content.manage' }, + { to: '/admin/partners', label: 'Partner-Logos', icon: 'shield', permission: 'content.manage' }, { to: '/admin/downloads', label: 'Downloads', icon: 'download', permission: 'downloads.manage' }, ], }, { title: 'Bildergalerie', links: [ - { to: '/admin/gallery-brands', label: 'Marken', icon: 'tag', permission: 'gallery.manage' }, - { to: '/admin/gallery-projects', label: 'Projekte', icon: 'image', permission: 'gallery.manage' }, + { to: '/admin/gallery-brands', label: 'Galerie-Marken', icon: 'image', permission: 'gallery.manage' }, + { to: '/admin/gallery-projects', label: 'Projekte & Fotos', icon: 'image', permission: 'gallery.manage' }, ], }, { - title: 'Kunden', + title: 'Firma & Aussehen', links: [ - { to: '/admin/contact-requests', label: 'Kontaktanfragen', icon: 'mail', permission: 'contact.manage', badge: newContactCount }, + { to: '/admin/settings/company', label: 'Firmendaten', icon: 'building', permission: 'settings.manage' }, + { to: '/admin/settings/design', label: 'Aussehen', icon: 'palette', permission: 'settings.manage' }, + { to: '/admin/settings/legal', label: 'Rechtstexte', icon: 'file', permission: 'settings.manage' }, + { to: '/admin/settings/maintenance', label: 'Wartungsmodus', icon: 'pause', permission: 'settings.manage' }, ], }, { - title: 'Verwaltung', + title: 'System (Experten)', links: [ { to: '/admin/users', label: 'Benutzer', icon: 'users', permission: 'users.manage' }, - { to: '/admin/permission-groups', label: 'Berechtigungsgruppen', icon: 'shield', permission: 'permission_groups.manage' }, - { to: '/admin/settings', label: 'Einstellungen', icon: 'sliders', permission: 'settings.manage' }, + { to: '/admin/permission-groups', label: 'Berechtigungsgruppen', icon: 'lock', permission: 'permission_groups.manage' }, + { to: '/admin/settings/email', label: 'E-Mail-Versand', icon: 'send', permission: 'system.admin' }, + { to: '/admin/settings/google', label: 'Google-Dienste', icon: 'globe', permission: 'system.admin' }, + { to: '/admin/settings/database', label: 'Datenbank', icon: 'server', permission: 'system.admin' }, + { to: '/admin/settings/export-import', label: 'Export & Import', icon: 'download', permission: 'system.admin' }, + { to: '/admin/settings/update', label: 'Updates', icon: 'refresh', permission: 'system.update' }, + { to: '/admin/settings/reset', label: 'Zurücksetzen', icon: 'trash', permission: 'system.admin' }, ], }, + { + title: null, + links: [{ to: '/admin/account', label: 'Mein Konto', icon: 'lock' }], + }, ] .map((group) => ({ ...group, links: group.links.filter((l) => !l.permission || hasPermission(l.permission)) })) .filter((group) => group.links.length > 0); @@ -138,6 +187,8 @@ export default function AdminLayout() { ); return ( + +
@@ -174,6 +225,15 @@ export default function AdminLayout() { Angemeldet als {user?.username}{user?.is_super_admin ? ' · Super-Admin' : ''}

+ + + Website öffnen +
+
); } diff --git a/hifi-src/src/components/CookieConsentBanner.jsx b/hifi-src/src/components/CookieConsentBanner.jsx index 22512ef..340794a 100644 --- a/hifi-src/src/components/CookieConsentBanner.jsx +++ b/hifi-src/src/components/CookieConsentBanner.jsx @@ -1,13 +1,16 @@ -import { useState } from 'react'; +import { useRef, useState } from 'react'; import { Link } from 'react-router-dom'; import { useCookieConsent } from '../context/CookieConsentContext.jsx'; import { useLanguage } from '../context/LanguageContext.jsx'; +import useDialog from '../hooks/useDialog.js'; function SettingsModal({ onClose }) { const { consent, saveCustom } = useCookieConsent(); const [external, setExternal] = useState(consent.external); const [analytics, setAnalytics] = useState(consent.analytics); const { t } = useLanguage(); + const dialogRef = useRef(null); + useDialog(dialogRef, true, onClose); return (
e.stopPropagation()} > diff --git a/hifi-src/src/components/GoogleAnalytics.jsx b/hifi-src/src/components/GoogleAnalytics.jsx index c66c34e..efbd48a 100644 --- a/hifi-src/src/components/GoogleAnalytics.jsx +++ b/hifi-src/src/components/GoogleAnalytics.jsx @@ -1,4 +1,5 @@ import { useEffect, useRef } from 'react'; +import { useLocation } from 'react-router-dom'; import { useCookieConsent } from '../context/CookieConsentContext.jsx'; import { useSiteSettings } from '../context/SiteSettingsContext.jsx'; @@ -9,6 +10,7 @@ export default function GoogleAnalytics() { const { consent } = useCookieConsent(); const { ga_measurement_id: measurementId } = useSiteSettings(); const loadedRef = useRef(false); + const location = useLocation(); useEffect(() => { if (!measurementId || !consent.analytics || loadedRef.current) return; @@ -25,8 +27,25 @@ export default function GoogleAnalytics() { } window.gtag = gtag; gtag('js', new Date()); - gtag('config', measurementId, { anonymize_ip: true }); + // Seitenaufrufe sendet unten der Routen-Effekt selbst - die Single-Page-App laedt bei + // einem Seitenwechsel nicht neu, ohne das zaehlte GA nur den ersten Aufruf zuverlaessig. + gtag('config', measurementId, { anonymize_ip: true, send_page_view: false }); }, [measurementId, consent.analytics]); + // Widerruf der Einwilligung im Cookie-Banner an GA weitergeben. + useEffect(() => { + if (!loadedRef.current || typeof window.gtag !== 'function') return; + window.gtag('consent', 'update', { analytics_storage: consent.analytics ? 'granted' : 'denied' }); + }, [consent.analytics]); + + useEffect(() => { + if (!consent.analytics || typeof window.gtag !== 'function') return; + window.gtag('event', 'page_view', { + page_path: location.pathname + location.search, + page_location: window.location.href, + page_title: document.title, + }); + }, [location.pathname, location.search, consent.analytics, measurementId]); + return null; } diff --git a/hifi-src/src/components/ImageUploadField.jsx b/hifi-src/src/components/ImageUploadField.jsx index caa2b83..26f77e1 100644 --- a/hifi-src/src/components/ImageUploadField.jsx +++ b/hifi-src/src/components/ImageUploadField.jsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import Cropper from 'react-easy-crop'; import { api } from '../api/client.js'; import { getCroppedImageBlob } from '../utils/cropImage.js'; +import { MAX_UPLOAD_BYTES, formatBytes } from '../utils/resizeImage.js'; function extensionForMime(mime) { if (mime === 'image/jpeg') return 'jpg'; @@ -66,6 +67,9 @@ export default function ImageUploadField({ value, onChange, label = 'Bild', aspe setError(''); try { const blob = await getCroppedImageBlob(cropSrc, croppedAreaPixels, cropMime); + if (blob.size > MAX_UPLOAD_BYTES) { + throw new Error(`Das Bild ist auch nach dem Verkleinern noch ${formatBytes(blob.size)} groß (max. 5 MB). Bitte als JPG statt PNG speichern oder einen kleineren Ausschnitt wählen.`); + } const formData = new FormData(); formData.append('file', blob, `zugeschnitten.${extensionForMime(cropMime)}`); const result = await api.post('/uploads', formData); @@ -108,6 +112,7 @@ export default function ImageUploadField({ value, onChange, label = 'Bild', aspe )} {uploading && Lädt hoch…}
+

JPG, PNG oder WebP. Große Fotos werden automatisch verkleinert.

{error &&

{error}

} {cropSrc && ( diff --git a/hifi-src/src/components/Navbar.jsx b/hifi-src/src/components/Navbar.jsx index 8b1790b..60875df 100644 --- a/hifi-src/src/components/Navbar.jsx +++ b/hifi-src/src/components/Navbar.jsx @@ -1,17 +1,17 @@ import { useEffect, useRef, useState } from 'react'; import { createPortal } from 'react-dom'; -import { Link, useLocation } from 'react-router-dom'; +import { Link, NavLink, useLocation } from 'react-router-dom'; import { LayoutDashboard, MessageCircle, Phone, ShoppingBag } from 'lucide-react'; import ThemeToggle from './ThemeToggle.jsx'; import { useAuth } from '../context/AuthContext.jsx'; import { useIsAreaHidden, useSiteSettings } from '../context/SiteSettingsContext.jsx'; import { useLanguage } from '../context/LanguageContext.jsx'; import logoDark from '../assets/logo-dark.png'; +import { telHref, waHref } from '../utils/contactLinks.js'; +import { trackEvent } from '../utils/analytics.js'; const SHOP_URL = 'https://www.audio4cars.de/'; -const digitsOnly = (value) => (value || '').replace(/[^\d+]/g, ''); - const ITEM_DELAY_MS = 70; const FLY_DURATION_MS = 500; @@ -152,6 +152,47 @@ export default function Navbar() { const transparent = isHome && !scrolled; + // Menue-Overlay als echter Dialog: Escape schliesst, Tab bleibt im Menue, die Seite + // dahinter scrollt nicht mit, und der Fokus springt beim Oeffnen auf "Schliessen". + const overlayRef = useRef(null); + const burgerRef = useRef(null); + useEffect(() => { + if (!open) return undefined; + const previousOverflow = document.body.style.overflow; + document.body.style.overflow = 'hidden'; + const focusTimer = setTimeout(() => overlayRef.current?.querySelector('button, a')?.focus(), 50); + const handleKeyDown = (e) => { + if (e.key === 'Escape') { + setOpen(false); + return; + } + if (e.key !== 'Tab' || !overlayRef.current) return; + const focusable = [...overlayRef.current.querySelectorAll('a[href], button')]; + if (!focusable.length) return; + const first = focusable[0]; + const last = focusable[focusable.length - 1]; + if (e.shiftKey && document.activeElement === first) { + e.preventDefault(); + last.focus(); + } else if (!e.shiftKey && document.activeElement === last) { + e.preventDefault(); + first.focus(); + } + }; + document.addEventListener('keydown', handleKeyDown); + return () => { + clearTimeout(focusTimer); + document.body.style.overflow = previousOverflow; + document.removeEventListener('keydown', handleKeyDown); + burgerRef.current?.focus({ preventScroll: true }); + }; + }, [open]); + + const desktopLinkClass = ({ isActive }) => + `rounded-md px-2.5 py-1.5 text-sm font-semibold transition ${ + isActive ? 'text-brand-400' : transparent ? 'text-white/90 hover:text-white' : 'text-neutral-300 hover:text-white' + }`; + useEffect(() => { if (open) { setMounted(true); @@ -215,8 +256,11 @@ export default function Navbar() {
+ {/* Ab Desktop-Breite die wichtigsten Seiten direkt sichtbar, ohne Umweg ueber das Menue. */} +
{/* Immer die Dark-Mode-Logovariante (weisse Wortmarke) - passend zur immer dunklen @@ -234,6 +285,18 @@ export default function Navbar() {
+ {phone && ( + trackEvent('contact_call')} + className={`mr-1 hidden items-center gap-2 rounded-full border px-3.5 py-1.5 text-sm font-semibold transition lg:inline-flex ${ + transparent ? 'border-white/40 text-white hover:bg-white/10' : 'border-neutral-700 text-neutral-200 hover:bg-neutral-800' + }`} + > + + {phone} + + )} {AdminIcon} {!open && } @@ -243,6 +306,10 @@ export default function Navbar() { {mounted && createPortal(
@@ -285,14 +352,15 @@ export default function Navbar() {
{phone && ( - + trackEvent('contact_call')} className={`flex items-center gap-2 text-sm font-semibold uppercase tracking-wide text-neutral-600 hover:text-brand-600 ${flyIn()}`} style={nextFly()}> {phone} )} {whatsapp && ( trackEvent('contact_whatsapp')} target="_blank" rel="noopener noreferrer" className={`flex items-center gap-2 text-sm font-semibold uppercase tracking-wide text-neutral-600 hover:text-brand-600 ${flyIn()}`} diff --git a/hifi-src/src/components/PublicLayout.jsx b/hifi-src/src/components/PublicLayout.jsx index cfbc562..bc06d38 100644 --- a/hifi-src/src/components/PublicLayout.jsx +++ b/hifi-src/src/components/PublicLayout.jsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { Suspense, useEffect, useState } from 'react'; import { Navigate, Outlet, useLocation } from 'react-router-dom'; import Navbar from './Navbar.jsx'; import Footer from './Footer.jsx'; @@ -59,6 +59,8 @@ const DEFAULT_SITE_SETTINGS = { page_loader_enabled: 1, has_downloads: false, hidden_areas: [], + price_note: null, + price_note_en: null, }; // Das Impressum (und die anderen rechtlichen Pflichtseiten) müssen laut § 5 DDG @@ -67,22 +69,86 @@ const DEFAULT_SITE_SETTINGS = { // verdeckt werden. const LEGAL_PATHS = ['/impressum', '/datenschutz', '/agb']; +// Letzter bekannter Stand von Einstellungen/Wartung aus dem Browser-Speicher: damit kann +// die Seite beim naechsten Besuch sofort rendern, statt auf die API zu warten. Der frische +// Stand vom Server ersetzt ihn direkt danach. +const SETTINGS_CACHE_KEY = 'hifi-site-settings'; +const STATUS_CACHE_KEY = 'hifi-maintenance'; +function readCache(key) { + try { + const raw = localStorage.getItem(key); + return raw ? JSON.parse(raw) : null; + } catch { + return null; + } +} +function writeCache(key, value) { + try { + localStorage.setItem(key, JSON.stringify(value)); + } catch { + // Speicher voll/gesperrt - dann eben ohne Cache + } +} + +const DAY_NAMES = { mon: 'Monday', tue: 'Tuesday', wed: 'Wednesday', thu: 'Thursday', fri: 'Friday', sat: 'Saturday', sun: 'Sunday' }; + +// Haelt die strukturierten Firmendaten fuer Google (index.html, id="ld-business") mit den +// im Admin gepflegten Kontaktdaten und Oeffnungszeiten synchron. +function updateBusinessJsonLd(settings) { + const script = document.getElementById('ld-business'); + if (!script) return; + try { + const data = JSON.parse(script.textContent); + const digits = (settings.phone || '').replace(/[^\d+]/g, ''); + if (digits) data.telephone = digits.startsWith('+') ? digits : `+49${digits.replace(/^0/, '')}`; + if (settings.contact_email) data.email = settings.contact_email; + data.address = { + '@type': 'PostalAddress', + streetAddress: settings.address_street || data.address?.streetAddress, + postalCode: settings.address_zip || data.address?.postalCode, + addressLocality: settings.address_city || data.address?.addressLocality, + addressCountry: 'DE', + }; + const hours = settings.business_hours; + if (hours && typeof hours === 'object') { + data.openingHoursSpecification = Object.entries(DAY_NAMES) + .filter(([key]) => hours[key] && !hours[key].closed && hours[key].open && hours[key].close) + .map(([key, day]) => ({ '@type': 'OpeningHoursSpecification', dayOfWeek: day, opens: hours[key].open, closes: hours[key].close })); + } + script.textContent = JSON.stringify(data); + } catch { + // Startwert aus index.html bleibt stehen + } +} + export default function PublicLayout() { - const [status, setStatus] = useState(null); - const [siteSettings, setSiteSettings] = useState(DEFAULT_SITE_SETTINGS); + const [cachedSettings] = useState(() => readCache(SETTINGS_CACHE_KEY)); + const [status, setStatus] = useState(() => readCache(STATUS_CACHE_KEY)); + const [siteSettings, setSiteSettings] = useState(() => + cachedSettings ? { ...DEFAULT_SITE_SETTINGS, ...cachedSettings } : DEFAULT_SITE_SETTINGS + ); // Erst rendern, wenn klar ist, welche Bereiche ausgeblendet sind - sonst blitzt eine - // ausgeblendete Seite/Sektion kurz auf, bevor die Einstellungen da sind. - const [siteSettingsLoaded, setSiteSettingsLoaded] = useState(false); + // ausgeblendete Seite/Sektion kurz auf. Mit Cache vom letzten Besuch geht es sofort los. + const [siteSettingsLoaded, setSiteSettingsLoaded] = useState(!!cachedSettings); const [textStyles, setTextStyles] = useState({}); const [customFonts, setCustomFonts] = useState([]); const { loading: authLoading, hasPermission } = useAuth(); const location = useLocation(); useEffect(() => { - api.get('/maintenance').then(setStatus).catch(() => setStatus(FALLBACK_STATUS)); + api + .get('/maintenance') + .then((data) => { + setStatus(data); + writeCache(STATUS_CACHE_KEY, data); + }) + .catch(() => setStatus((current) => current || FALLBACK_STATUS)); api .get('/site-settings') - .then(setSiteSettings) + .then((data) => { + setSiteSettings({ ...DEFAULT_SITE_SETTINGS, ...data }); + writeCache(SETTINGS_CACHE_KEY, data); + }) .catch(() => {}) .finally(() => setSiteSettingsLoaded(true)); api.get('/text-styles').then(setTextStyles).catch(() => {}); @@ -100,7 +166,13 @@ export default function PublicLayout() { } }, [siteSettings.site_font]); - if (status === null || !siteSettingsLoaded || authLoading) { + useEffect(() => { + if (siteSettingsLoaded) updateBusinessJsonLd(siteSettings); + }, [siteSettings, siteSettingsLoaded]); + + // Auf den Login-Status wird nur gewartet, wenn die Wartung aktiv ist (dann entscheidet er, + // ob ein Admin die Seite trotzdem sieht) - normale Besucher sehen die Seite sofort. + if (status === null || !siteSettingsLoaded || (status.global?.enabled && authLoading)) { return
; } @@ -132,7 +204,13 @@ export default function PublicLayout() { die globale Einstellung. */} {/* Im Dashboard ausgeblendete Seiten (inkl. Unterseiten) -> Startseite. */} - {isPathHidden(location.pathname, siteSettings.hidden_areas) ? : } + {isPathHidden(location.pathname, siteSettings.hidden_areas) ? ( + + ) : ( + }> + + + )}