From 496477285f98f69d6e74de00bff4af29ce88898f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 20 Oct 2026 17:21:00 +0000 Subject: [PATCH] Admin: Website-Inhalte im neuen Stil - Gemeinsames Listen-Geruest (EntityList): sortierbare Liste, ganze Zeile oeffnet das Seitenpanel, Leerzustand und Ladeplatzhalter - FAQ, Partner-Logos, Leistungen und Downloads darauf umgestellt - Downloads: Datei per Ziehen ablegen, Fortschritt beim Hochladen, Sichtbarkeit direkt in der Zeile, Zugriffsschutz als eigene Karte - Startseite: Abschnitte links als nummerierte Liste, Sprache und Position als Umschalter, Felder im einheitlichen Stil Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01R5qHQ6FkdkREoPVmRJ5V77 --- hifi-src/src/components/admin/EntityList.jsx | 219 ++ hifi-src/src/components/ui/index.jsx | 50 +- hifi-src/src/pages/admin/Downloads.jsx | 456 +-- hifi-src/src/pages/admin/Faqs.jsx | 267 +- hifi-src/src/pages/admin/HomeSections.jsx | 462 ++- hifi-src/src/pages/admin/Partners.jsx | 216 +- hifi-src/src/pages/admin/Services.jsx | 327 +- hifi/assets/AGB-BcE4RXz8.js | 1 - hifi/assets/AGB-DfbdRaCi.js | 1 + ...ZsnsJVe.js => AccountSettings-Bzc5jN0d.js} | 2 +- ...ers-Fr-eVHu9.js => AdminUsers-DStaV5dB.js} | 2 +- ...{Brands-DZJJVTHW.js => Brands-Cue1zlYN.js} | 2 +- ...xgSq.js => ConnectionSettings-BsmufJ0A.js} | 2 +- ...u-W19Bw.js => ContactRequests-C3G1TDKs.js} | 2 +- ...mxGld.js => CountdownSettings-Ch_XjyMD.js} | 2 +- ...oard-Btsus4A1.js => Dashboard-D0-IyNey.js} | 2 +- ...OyWi6m.js => DatabaseSettings-DmXlgblZ.js} | 2 +- ...tz-rYBB42JR.js => Datenschutz-Cbd2sLBg.js} | 2 +- hifi/assets/Downloads-BQEggK2T.js | 1 + hifi/assets/Downloads-C1grCCI7.js | 1 - ...-TbgX_HNq.js => DownloadsPage-DEwnFFuO.js} | 2 +- ...-RGvTcni6.js => EmailSettings-BuIx_PTK.js} | 2 +- hifi/assets/EntityList-YEt417Jn.js | 1 + ...QU.js => ExportImportSettings-Cz9tQe1l.js} | 2 +- hifi/assets/Faqs-B4EQzMJD.js | 1 - hifi/assets/Faqs-C03NTJ97.js | 1 + ...xWwAbM.js => GalleryBrandPage-cAKGZvM1.js} | 2 +- ...-B8ynijo6.js => GalleryBrands-C30jLvnm.js} | 2 +- ...mduDaQ7.js => GalleryOverview-CIoNImpG.js} | 2 +- ...-fPY9NppD.js => GalleryPhotos-B8W_x_sE.js} | 2 +- ...qT3g.js => GalleryProjectPage-m3qYRZRB.js} | 2 +- ...uO_Lsjs.js => GalleryProjects-VPAkRVZ4.js} | 2 +- hifi/assets/HomeSections-BMM3uSGn.js | 1 - hifi/assets/HomeSections-CByTimzs.js | 1 + ...C4h0WQan.js => ImageOptimizer-Bugc-kOl.js} | 2 +- ...sI9IyN.js => ImageUploadField-whEDLUwi.js} | 2 +- hifi/assets/Impressum-B3hSSqjg.js | 1 + hifi/assets/Impressum-BPeHwGSm.js | 1 - ...-Dof8ROKZ.js => LegalPageView-Bsr9mTcC.js} | 2 +- ...-DGY4BB_M.js => LegalSettings-kQ8vgOEk.js} | 2 +- .../{Login-CPYyTbD2.js => Login-BaxLN7EH.js} | 2 +- ...4LK.js => MaintenanceSettings-DkwdsE8p.js} | 2 +- ...{Models-BGdhC0xo.js => Models-CXTBpfMY.js} | 2 +- ...kages-IHdehtTN.js => Packages-BjKITmR5.js} | 4 +- hifi/assets/Partners-CEeYWBtx.js | 1 + hifi/assets/Partners-Dhaymv5o.js | 1 - ...ETEHt-.js => PermissionGroups-DYCZxxNS.js} | 2 +- hifi/assets/ResetSettings-CkVt1n2j.js | 1 - hifi/assets/ResetSettings-dlncWxdt.js | 1 + ...BfTdzdTx.js => RichTextEditor-fvaAjnOG.js} | 2 +- ...aveBar-DOowzUmB.js => SaveBar-fY3yOEcb.js} | 2 +- hifi/assets/Services-01Sqim6G.js | 1 - hifi/assets/Services-Dpn87zQS.js | 1 + hifi/assets/SettingsLayout-BrNaDsnv.js | 1 - hifi/assets/SettingsLayout-CA8VoJdg.js | 1 + ...rd-C5JtftCY.js => SetupWizard-84I94Eqf.js} | 2 +- ...t-BSPtdpVe.js => SortableList-DLBSwniA.js} | 2 +- ...qjcTn1V.js => TextStyleWidget-BNnwr5HP.js} | 2 +- ...CD9ojf8y.js => UpdateSettings-vBqPTZn0.js} | 2 +- ...eG.js => VehicleCatalogDialog-C3HKUZ9b.js} | 2 +- ...ite-Bw_4-kwv.js => ViewOnSite-BydlOs3r.js} | 2 +- ...RMzJYT-.js => WebsiteSettings-BrzObAXl.js} | 2 +- hifi/assets/eye-Y7R0U8m-.js | 11 - ...-CpzQl3F1.js => grip-vertical-CvU3AksZ.js} | 2 +- ...y-DapGPLCJ.js => iconRegistry-CfxXydV3.js} | 3260 +++++++++-------- hifi/assets/index-B6VgT9oo.css | 1 - .../{index-hptrrCTJ.js => index-DXRY3i3l.js} | 20 +- hifi/assets/index-oF_2tBZ5.css | 1 + .../{music-kCf6GhXx.js => music-D-mBCZio.js} | 2 +- ...m-xa1-4fn5.js => sortable.esm-BO8aRrry.js} | 2 +- ...rash-2-DYD8N6Uj.js => trash-2-CM23Tqj7.js} | 2 +- hifi/index.html | 4 +- 72 files changed, 2628 insertions(+), 2767 deletions(-) create mode 100644 hifi-src/src/components/admin/EntityList.jsx delete mode 100644 hifi/assets/AGB-BcE4RXz8.js create mode 100644 hifi/assets/AGB-DfbdRaCi.js rename hifi/assets/{AccountSettings-DZsnsJVe.js => AccountSettings-Bzc5jN0d.js} (99%) rename hifi/assets/{AdminUsers-Fr-eVHu9.js => AdminUsers-DStaV5dB.js} (98%) rename hifi/assets/{Brands-DZJJVTHW.js => Brands-Cue1zlYN.js} (93%) rename hifi/assets/{ConnectionSettings-L-jwxgSq.js => ConnectionSettings-BsmufJ0A.js} (98%) rename hifi/assets/{ContactRequests-Du-W19Bw.js => ContactRequests-C3G1TDKs.js} (98%) rename hifi/assets/{CountdownSettings-BCrmxGld.js => CountdownSettings-Ch_XjyMD.js} (98%) rename hifi/assets/{Dashboard-Btsus4A1.js => Dashboard-D0-IyNey.js} (99%) rename hifi/assets/{DatabaseSettings-BEOyWi6m.js => DatabaseSettings-DmXlgblZ.js} (98%) rename hifi/assets/{Datenschutz-rYBB42JR.js => Datenschutz-Cbd2sLBg.js} (54%) create mode 100644 hifi/assets/Downloads-BQEggK2T.js delete mode 100644 hifi/assets/Downloads-C1grCCI7.js rename hifi/assets/{DownloadsPage-TbgX_HNq.js => DownloadsPage-DEwnFFuO.js} (97%) rename hifi/assets/{EmailSettings-RGvTcni6.js => EmailSettings-BuIx_PTK.js} (98%) create mode 100644 hifi/assets/EntityList-YEt417Jn.js rename hifi/assets/{ExportImportSettings-BgiuQEQU.js => ExportImportSettings-Cz9tQe1l.js} (95%) delete mode 100644 hifi/assets/Faqs-B4EQzMJD.js create mode 100644 hifi/assets/Faqs-C03NTJ97.js rename hifi/assets/{GalleryBrandPage-DRxWwAbM.js => GalleryBrandPage-cAKGZvM1.js} (96%) rename hifi/assets/{GalleryBrands-B8ynijo6.js => GalleryBrands-C30jLvnm.js} (93%) rename hifi/assets/{GalleryOverview-XmduDaQ7.js => GalleryOverview-CIoNImpG.js} (96%) rename hifi/assets/{GalleryPhotos-fPY9NppD.js => GalleryPhotos-B8W_x_sE.js} (94%) rename hifi/assets/{GalleryProjectPage-DazrqT3g.js => GalleryProjectPage-m3qYRZRB.js} (98%) rename hifi/assets/{GalleryProjects-CuO_Lsjs.js => GalleryProjects-VPAkRVZ4.js} (95%) delete mode 100644 hifi/assets/HomeSections-BMM3uSGn.js create mode 100644 hifi/assets/HomeSections-CByTimzs.js rename hifi/assets/{ImageOptimizer-C4h0WQan.js => ImageOptimizer-Bugc-kOl.js} (97%) rename hifi/assets/{ImageUploadField-CasI9IyN.js => ImageUploadField-whEDLUwi.js} (99%) create mode 100644 hifi/assets/Impressum-B3hSSqjg.js delete mode 100644 hifi/assets/Impressum-BPeHwGSm.js rename hifi/assets/{LegalPageView-Dof8ROKZ.js => LegalPageView-Bsr9mTcC.js} (82%) rename hifi/assets/{LegalSettings-DGY4BB_M.js => LegalSettings-kQ8vgOEk.js} (95%) rename hifi/assets/{Login-CPYyTbD2.js => Login-BaxLN7EH.js} (98%) rename hifi/assets/{MaintenanceSettings-DCZYq4LK.js => MaintenanceSettings-DkwdsE8p.js} (98%) rename hifi/assets/{Models-BGdhC0xo.js => Models-CXTBpfMY.js} (96%) rename hifi/assets/{Packages-IHdehtTN.js => Packages-BjKITmR5.js} (96%) create mode 100644 hifi/assets/Partners-CEeYWBtx.js delete mode 100644 hifi/assets/Partners-Dhaymv5o.js rename hifi/assets/{PermissionGroups-BnETEHt-.js => PermissionGroups-DYCZxxNS.js} (98%) delete mode 100644 hifi/assets/ResetSettings-CkVt1n2j.js create mode 100644 hifi/assets/ResetSettings-dlncWxdt.js rename hifi/assets/{RichTextEditor-BfTdzdTx.js => RichTextEditor-fvaAjnOG.js} (99%) rename hifi/assets/{SaveBar-DOowzUmB.js => SaveBar-fY3yOEcb.js} (93%) delete mode 100644 hifi/assets/Services-01Sqim6G.js create mode 100644 hifi/assets/Services-Dpn87zQS.js delete mode 100644 hifi/assets/SettingsLayout-BrNaDsnv.js create mode 100644 hifi/assets/SettingsLayout-CA8VoJdg.js rename hifi/assets/{SetupWizard-C5JtftCY.js => SetupWizard-84I94Eqf.js} (98%) rename hifi/assets/{SortableList-BSPtdpVe.js => SortableList-DLBSwniA.js} (89%) rename hifi/assets/{TextStyleWidget-0qjcTn1V.js => TextStyleWidget-BNnwr5HP.js} (97%) rename hifi/assets/{UpdateSettings-CD9ojf8y.js => UpdateSettings-vBqPTZn0.js} (99%) rename hifi/assets/{VehicleCatalogDialog-DWOTD4eG.js => VehicleCatalogDialog-C3HKUZ9b.js} (99%) rename hifi/assets/{ViewOnSite-Bw_4-kwv.js => ViewOnSite-BydlOs3r.js} (84%) rename hifi/assets/{WebsiteSettings-BRMzJYT-.js => WebsiteSettings-BrzObAXl.js} (97%) delete mode 100644 hifi/assets/eye-Y7R0U8m-.js rename hifi/assets/{grip-vertical-CpzQl3F1.js => grip-vertical-CvU3AksZ.js} (91%) rename hifi/assets/{iconRegistry-DapGPLCJ.js => iconRegistry-CfxXydV3.js} (80%) delete mode 100644 hifi/assets/index-B6VgT9oo.css rename hifi/assets/{index-hptrrCTJ.js => index-DXRY3i3l.js} (87%) create mode 100644 hifi/assets/index-oF_2tBZ5.css rename hifi/assets/{music-kCf6GhXx.js => music-D-mBCZio.js} (98%) rename hifi/assets/{sortable.esm-xa1-4fn5.js => sortable.esm-BO8aRrry.js} (99%) rename hifi/assets/{trash-2-DYD8N6Uj.js => trash-2-CM23Tqj7.js} (95%) diff --git a/hifi-src/src/components/admin/EntityList.jsx b/hifi-src/src/components/admin/EntityList.jsx new file mode 100644 index 0000000..4771a68 --- /dev/null +++ b/hifi-src/src/components/admin/EntityList.jsx @@ -0,0 +1,219 @@ +import { useCallback, useEffect, useMemo, useState } from 'react'; +import { api } from '../../api/client.js'; +import { useToast, useUnsavedChanges } from '../../context/AdminUiContext.jsx'; +import SortableList, { saveReorder } from './SortableList.jsx'; +import { Card, EmptyState, Icon, IconButton, Input } from '../ui/index.jsx'; + +// Gemeinsames Geruest der einfachen Listen-Seiten im Admin (FAQ, Partner, Leistungen, +// Downloads, ...): Liste mit Ziehen-zum-Sortieren, ganze Zeile = Bearbeiten im Seitenpanel. +// Muster wie Fahrzeugmarken/Modelle - die Seite liefert nur Felder und Zeileninhalt. + +/** + * Laden, Bearbeiten, Speichern, Loeschen und Sortieren einer Liste. + * - endpoint: z. B. '/faqs' (GET/POST endpoint, PUT/DELETE endpoint/) + * - reorderKey: Schluessel fuer PUT /reorder/ + * - toForm(item): Formularwerte aus einem Eintrag + * - save({ editing, form, items }): optional eigenes Speichern (z. B. mit Datei-Upload) + * - labels: { created, saved, deleted } + */ +export function useEntityEditor({ endpoint, listEndpoint, reorderKey, emptyForm, toForm, toPayload = (f) => f, save, labels, source }) { + const toast = useToast(); + const [items, setItems] = useState(null); + const [editing, setEditing] = useState(null); // null = zu, 'new' = neu, sonst id + const [form, setForm] = useState(emptyForm); + const [initialForm, setInitialForm] = useState(emptyForm); + const [extraDirty, setExtraDirty] = useState(false); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(''); + + const dirty = extraDirty || JSON.stringify(form) !== JSON.stringify(initialForm); + useUnsavedChanges(editing !== null && dirty, source); + + const load = useCallback( + () => + api + .get(listEndpoint || endpoint) + .then(setItems) + .catch((err) => { + setItems((prev) => prev || []); + toast.error(err.message); + }), + // eslint-disable-next-line react-hooks/exhaustive-deps + [endpoint, listEndpoint], + ); + + useEffect(() => { + load(); + }, [load]); + + const openPanel = (item) => { + const next = item ? toForm(item) : emptyForm; + setEditing(item ? item.id : 'new'); + setForm(next); + setInitialForm(next); + setExtraDirty(false); + setError(''); + }; + + const forceClose = () => { + setEditing(null); + setExtraDirty(false); + }; + + const closePanel = () => { + if (dirty && !window.confirm('Ungespeicherte Änderungen verwerfen?')) return; + forceClose(); + }; + + const submit = async (e) => { + e?.preventDefault(); + setError(''); + setSaving(true); + try { + if (save) { + await save({ editing, form, items: items || [] }); + } else if (editing !== 'new') { + await api.put(`${endpoint}/${editing}`, toPayload(form)); + } else { + const sort = (items || []).reduce((max, i) => Math.max(max, Number(i.sort_order) || 0), 0) + 10; + await api.post(endpoint, { ...toPayload(form), sort_order: sort }); + } + toast.success(editing === 'new' ? labels.created : labels.saved); + setInitialForm(form); + forceClose(); + load(); + } catch (err) { + setError(err.message); + } finally { + setSaving(false); + } + }; + + const remove = async (item, question) => { + if (!window.confirm(question)) return; + try { + await api.delete(`${endpoint}/${item.id}`); + if (editing === item.id) forceClose(); + toast.success(labels.deleted); + load(); + } catch (err) { + toast.error(`Löschen fehlgeschlagen: ${err.message}`); + } + }; + + const reorder = async (reordered) => { + const previous = items; + setItems(reordered); + try { + setItems(await saveReorder(reorderKey, reordered)); + toast.success('Reihenfolge gespeichert.'); + } catch (err) { + setItems(previous); + toast.error(`Reihenfolge konnte nicht gespeichert werden: ${err.message}`); + } + }; + + return { + items, + setItems, + load, + editing, + isNew: editing === 'new', + form, + setForm, + change: (patch) => setForm((f) => ({ ...f, ...patch })), + setExtraDirty, + dirty, + saving, + error, + setError, + openPanel, + closePanel, + submit, + remove, + reorder, + }; +} + +/** + * Karte mit sortierbarer Liste. renderRow(item) liefert { media, title, subtitle, actions, muted }. + * Ab `searchFrom` Eintraegen erscheint ein Suchfeld (Sortieren ist waehrenddessen aus). + */ +export function EntityListCard({ items, onReorder, onOpen, onDelete, renderRow, empty, searchFrom = 10, searchText, searchPlaceholder = 'Suchen …', editingId }) { + const [query, setQuery] = useState(''); + const visible = useMemo(() => { + const q = query.trim().toLowerCase(); + if (!q || !items) return items || []; + return items.filter((item) => (searchText ? searchText(item) : '').toLowerCase().includes(q)); + }, [items, query, searchText]); + const filtering = query.trim() !== ''; + + return ( + + {items && items.length >= searchFrom && searchText && ( +
+
+ + setQuery(e.target.value)} placeholder={searchPlaceholder} className="h-9 pl-9" /> +
+
+ )} + {items === null ? ( +
    + {[0, 1, 2].map((i) => ( +
  • + + +
  • + ))} +
+ ) : items.length === 0 ? ( + + ) : visible.length === 0 ? ( +

Nichts gefunden für „{query}“.

+ ) : ( + + {(item, handle) => { + const row = renderRow(item); + return ( +
+ {handle} + +
+ {row.actions} + onOpen(item)} /> + onDelete(item)} /> +
+
+ ); + }} +
+ )} +
+ ); +} + +/** Quadratisches Vorschaufeld fuer Listenzeilen: Bild, Symbol oder Platzhalter. */ +export function RowMedia({ src, icon = 'image', contain = false, className = '' }) { + return src ? ( + + ) : ( + + + + ); +} diff --git a/hifi-src/src/components/ui/index.jsx b/hifi-src/src/components/ui/index.jsx index 9cd2b1d..2f7e4c4 100644 --- a/hifi-src/src/components/ui/index.jsx +++ b/hifi-src/src/components/ui/index.jsx @@ -1,7 +1,7 @@ // Gemeinsame Bausteine fuer den Admin: Knoepfe, Felder, Karten, Seitenkopf usw. Statt die // Tailwind-Klassen auf jeder Seite neu zu schreiben (frueher ~80 kopierte Feld-Stile), kommt // das Aussehen von hier - eine Aenderung wirkt dann ueberall gleich. -import { cloneElement, forwardRef, isValidElement, useId, useRef } from 'react'; +import { cloneElement, forwardRef, isValidElement, useId, useRef, useState } from 'react'; import { Link } from 'react-router-dom'; import useDialog from '../../hooks/useDialog.js'; @@ -239,6 +239,54 @@ export function SlideOver({ open, onClose, title, description, headerExtra, chil ); } +/** + * Ablageflaeche fuer eine Datei: hineinziehen oder klicken. Zeigt die gewaehlte Datei mit + * Groesse; `current` beschreibt die schon vorhandene Datei (z. B. beim Ersetzen). + */ +export function FileDrop({ file, onChange, accept, hint, current, disabled }) { + const id = useId(); + const [over, setOver] = useState(false); + const pick = (f) => !disabled && f && onChange(f); + const size = (bytes) => (bytes >= 1048576 ? `${(bytes / 1048576).toFixed(1).replace('.', ',')} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`); + return ( + + ); +} + /** Umschalter mit wenigen festen Moeglichkeiten (statt Auswahlliste). options: [{ value, label }] */ export function Segmented({ value, onChange, options, size = 'md', className }) { return ( diff --git a/hifi-src/src/pages/admin/Downloads.jsx b/hifi-src/src/pages/admin/Downloads.jsx index 38a55bc..216b6c6 100644 --- a/hifi-src/src/pages/admin/Downloads.jsx +++ b/hifi-src/src/pages/admin/Downloads.jsx @@ -1,16 +1,14 @@ -import { useEffect, useRef, useState } from 'react'; -import { Eye, EyeOff } from 'lucide-react'; +import { useEffect, useState } from 'react'; import { api, API_BASE } from '../../api/client.js'; -import { ALLOWED_DOWNLOAD_EXTENSIONS, formatFileSize } from '../../utils/downloads.js'; -import SortableList, { saveReorder } from '../../components/admin/SortableList.jsx'; -import ViewOnSite from '../../components/admin/ViewOnSite.jsx'; -import { useToast, useUnsavedChanges } from '../../context/AdminUiContext.jsx'; - -const inputCls = - 'w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900'; +import { ALLOWED_DOWNLOAD_EXTENSIONS, fileKind, formatFileSize } from '../../utils/downloads.js'; +import { useToast } from '../../context/AdminUiContext.jsx'; +import { Badge, Button, Card, Field, FileDrop, IconButton, Input, PageHeader, SlideOver, Textarea } from '../../components/ui/index.jsx'; +import { EntityListCard, RowMedia, useEntityEditor } from '../../components/admin/EntityList.jsx'; const emptyForm = { title: '', description: '', sort_order: 0 }; +const KIND_ICONS = { audio: 'play', video: 'play', image: 'image' }; + // fetch() meldet keinen Upload-Fortschritt - bei Songs mit 50+ MB soll man aber sehen, dass // etwas passiert. Daher hier XMLHttpRequest statt api.post. function uploadWithProgress(path, formData, onProgress) { @@ -42,10 +40,11 @@ function uploadWithProgress(path, formData, onProgress) { // Optionales Zugangspasswort fuer /downloads (app_settings.downloads_password, leer = // oeffentlich) - bewusst im Klartext einsehbar, es ist ein Code zum Weitergeben an Kunden. function AccessSettings() { + const toast = useToast(); const [saved, setSaved] = useState(undefined); // undefined = laedt, null = oeffentlich const [value, setValue] = useState(''); const [busy, setBusy] = useState(false); - const [message, setMessage] = useState(null); // { kind: 'ok' | 'error', text } + const [error, setError] = useState(''); useEffect(() => { api @@ -54,141 +53,115 @@ function AccessSettings() { setSaved(res.password); setValue(res.password || ''); }) - .catch((err) => setMessage({ kind: 'error', text: err.message })); + .catch((err) => setError(err.message)); }, []); const handleSave = async (e) => { e.preventDefault(); setBusy(true); - setMessage(null); + setError(''); try { const res = await api.put('/settings/downloads', { password: value }); setSaved(res.password); setValue(res.password || ''); - setMessage({ - kind: 'ok', - text: res.password ? 'Gespeichert – der Bereich ist jetzt geschützt.' : 'Gespeichert – der Bereich ist jetzt öffentlich.', - }); - } catch (err) { - setMessage({ kind: 'error', text: err.message }); - } finally { - setBusy(false); - } - }; - - return ( -
-

Zugriffsschutz

-

- {saved === undefined && 'Lädt…'} - {saved === null && 'Öffentlich – jeder, der die Seite aufruft, sieht die Dateien.'} - {typeof saved === 'string' && 'Geschützt – Besucher müssen zuerst das Passwort eingeben.'} -

-
- - setValue(e.target.value)} className={inputCls} /> -

- Das Passwort an die Kunden weitergeben – es bleibt hier jederzeit einsehbar. Direkte Links zu einzelnen - Dateien funktionieren auch ohne Passwort; wer freigeschaltet hat, könnte sie also weitergeben. -

-
- {message && ( -

{message.text}

- )} - -
- ); -} - -export default function Downloads() { - const [downloads, setDownloads] = useState([]); - const [form, setForm] = useState(emptyForm); - const [file, setFile] = useState(null); - const [editingId, setEditingId] = useState(null); - const [progress, setProgress] = useState(null); // 0..1 waehrend eines Uploads - const [busy, setBusy] = useState(false); - const [error, setError] = useState(''); - const [visibilityBusyId, setVisibilityBusyId] = useState(null); - const [savedForm, setSavedForm] = useState(emptyForm); - const fileInputRef = useRef(null); - const formRef = useRef(null); - const toast = useToast(); - - useUnsavedChanges(!!file || JSON.stringify(form) !== JSON.stringify(savedForm), 'downloads'); - - const load = () => api.get('/downloads/manage').then(setDownloads); - - useEffect(() => { - load(); - }, []); - - const resetForm = () => { - setEditingId(null); - setForm(emptyForm); - setSavedForm(emptyForm); - setFile(null); - setError(''); - if (fileInputRef.current) fileInputRef.current.value = ''; - }; - - const startEdit = (item) => { - resetForm(); - setEditingId(item.id); - const next = { title: item.title, description: item.description || '', sort_order: item.sort_order }; - setForm(next); - setSavedForm(next); - formRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }); - }; - - const handleSubmit = async (e) => { - e.preventDefault(); - if (!editingId && !file) { - setError('Bitte eine Datei auswählen.'); - return; - } - setBusy(true); - setError(''); - try { - if (editingId) { - await api.put(`/downloads/${editingId}`, form); - if (file) { - const data = new FormData(); - data.append('file', file); - setProgress(0); - await uploadWithProgress(`/downloads/${editingId}/file`, data, setProgress); - } - } else { - const data = new FormData(); - data.append('file', file); - data.append('title', form.title); - data.append('description', form.description); - setProgress(0); - await uploadWithProgress('/downloads', data, setProgress); - } - toast.success(editingId ? 'Download gespeichert.' : 'Datei hochgeladen.'); - resetForm(); - load(); + toast.success(res.password ? 'Gespeichert – der Bereich ist jetzt geschützt.' : 'Gespeichert – der Bereich ist jetzt öffentlich.'); } catch (err) { setError(err.message); } finally { setBusy(false); - setProgress(null); } }; + const unchanged = (saved || '') === value.trim(); + + return ( + Geschützt : Öffentlich + } + > +
+
+ + setValue(e.target.value)} placeholder="Leer lassen = öffentlich" /> + + +
+

+ Das Passwort bleibt hier jederzeit einsehbar. Direkte Links zu einzelnen Dateien funktionieren auch ohne Passwort. +

+
+
+ ); +} + +export default function Downloads() { + const toast = useToast(); + const [file, setFile] = useState(null); + const [progress, setProgress] = useState(null); // 0..1 waehrend eines Uploads + const [visibilityBusyId, setVisibilityBusyId] = useState(null); + + const ed = useEntityEditor({ + endpoint: '/downloads', + listEndpoint: '/downloads/manage', + reorderKey: 'downloads', + source: 'downloads', + emptyForm, + toForm: (d) => ({ title: d.title, description: d.description || '', sort_order: d.sort_order }), + labels: { created: 'Datei hochgeladen.', saved: 'Download gespeichert.', deleted: 'Download gelöscht.' }, + save: async ({ editing, form }) => { + try { + if (editing !== 'new') { + await api.put(`/downloads/${editing}`, form); + if (file) { + const data = new FormData(); + data.append('file', file); + setProgress(0); + await uploadWithProgress(`/downloads/${editing}/file`, data, setProgress); + } + } else { + const data = new FormData(); + data.append('file', file); + data.append('title', form.title); + data.append('description', form.description); + setProgress(0); + await uploadWithProgress('/downloads', data, setProgress); + } + setFile(null); + } finally { + setProgress(null); + } + }, + }); + const { form, change } = ed; + const current = ed.isNew ? null : (ed.items || []).find((d) => d.id === ed.editing); + + const openPanel = (item) => { + setFile(null); + ed.openPanel(item); + }; + + const pickFile = (f) => { + setFile(f); + ed.setExtraDirty(true); + }; + + const submit = (e) => { + e.preventDefault(); + if (ed.isNew && !file) { + ed.setError('Bitte eine Datei auswählen.'); + return; + } + ed.submit(); + }; + const toggleVisibility = async (item) => { setVisibilityBusyId(item.id); try { const res = await api.patch(`/downloads/${item.id}/visibility`, { is_hidden: !item.is_hidden }); - setDownloads((ds) => ds.map((d) => (d.id === item.id ? { ...d, is_hidden: res.is_hidden } : d))); + ed.setItems((ds) => ds.map((d) => (d.id === item.id ? { ...d, is_hidden: res.is_hidden } : d))); toast.success(res.is_hidden ? `„${item.title}“ ist jetzt ausgeblendet.` : `„${item.title}“ ist wieder sichtbar.`); } catch (err) { toast.error(`Sichtbarkeit konnte nicht geändert werden: ${err.message}`); @@ -197,142 +170,84 @@ export default function Downloads() { } }; - const handleDelete = async (item) => { - if (!confirm(`"${item.title}" inkl. Datei wirklich löschen?`)) return; - try { - await api.delete(`/downloads/${item.id}`); - if (editingId === item.id) resetForm(); - toast.success('Download gelöscht.'); - load(); - } catch (err) { - toast.error(`Löschen fehlgeschlagen: ${err.message}`); - } - }; - - const handleReorder = async (reordered) => { - const previous = downloads; - setDownloads(reordered); - try { - setDownloads(await saveReorder('downloads', reordered)); - toast.success('Reihenfolge gespeichert.'); - } catch (err) { - setDownloads(previous); - toast.error(`Reihenfolge konnte nicht gespeichert werden: ${err.message}`); - } - }; - return ( -
-
-
-

Downloads

- -
-

- Dateien, die Kunden auf der Seite{' '} - /downloads{' '} - anhören bzw. herunterladen können, z. B. Songs oder Anleitungen. Der Menüpunkt „Downloads“ erscheint auf - der Website automatisch, sobald mindestens eine Datei sichtbar ist. Ohne Zugangspasswort (siehe - „Zugriffsschutz“) ist die Seite öffentlich. Reihenfolge am Griff links per Ziehen ändern. -

-
- - - - - - - - - - - - {(item, handle) => ( - <> - - - - - - - )} - -
ReihenfolgeTitel / DateiGrößeWebsiteAktionen
{handle} -

{item.title}

- - {item.file_name} - -
{formatFileSize(item.file_size)} - - - - -
- {downloads.length === 0 && ( -

Noch keine Dateien hochgeladen.

- )} -
-
+
+ + + + + } + /> -
-
-

{editingId ? 'Download bearbeiten' : 'Neue Datei hochladen'}

-
- - ed.remove(d, `„${d.title}“ inkl. Datei wirklich löschen?`)} + searchText={(d) => `${d.title} ${d.file_name}`} + searchPlaceholder="Datei suchen …" + empty={{ + icon: 'download', + title: 'Noch keine Dateien', + description: 'Lade z. B. Demo-Songs oder Bedienungsanleitungen hoch.', + actions: , + }} + renderRow={(d) => ({ + media: , + title: d.title, + subtitle: ( + <> + {!!d.is_hidden && Ausgeblendet} + {d.file_name} · {formatFileSize(d.file_size)} + + ), + muted: !!d.is_hidden, + actions: ( + toggleVisibility(d)} + /> + ), + })} + /> + + + + + + + + } + > + {ed.error &&

{ed.error}

} + + `.${ext}`).join(',')} - onChange={(e) => setFile(e.target.files?.[0] || null)} - className="block w-full text-sm text-neutral-600 file:mr-3 file:rounded-md file:border-0 file:bg-brand-500 file:px-3 file:py-2 file:text-sm file:font-semibold file:text-white hover:file:bg-brand-600 dark:text-neutral-300" + current={current ? `${current.file_name} (${formatFileSize(current.file_size)})` : null} + hint="Musik, Videos, PDFs, Bilder, Office-Dateien oder ZIP. Andere Typen bitte als ZIP." /> -

- Musik (MP3, WAV, FLAC, …), Videos, PDFs, Bilder, Office-Dokumente oder ZIP-Archive. Andere Dateitypen bitte als ZIP hochladen. -

-
-
- - setForm({ ...form, title: e.target.value })} - placeholder={editingId ? '' : 'Leer lassen = Dateiname'} - className={inputCls} - /> -
-
- -