Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0174bfXbDqAn2M7TjkdqGCrn
3 lines
4.4 KiB
JavaScript
3 lines
4.4 KiB
JavaScript
import{g as z,r as l,q as B,c as d,j as t,L as C}from"./index-s3eIr1sf.js";import{S as M,s as D}from"./SortableList-CshCy5di.js";import{V as G}from"./ViewOnSite-DMq1GxG3.js";import{r as L,M as A,f as I}from"./resizeImage-C6PvAwh0.js";import"./sortable.esm-CkNy0jji.js";import"./grip-vertical-CCNCGx9L.js";function J(){const{projectId:m}=z(),[u,h]=l.useState([]),[c,v]=l.useState(null),[f,j]=l.useState(""),[b,w]=l.useState(!1),[$,y]=l.useState(""),p=l.useRef(null),s=B(),x=()=>d.get(`/gallery-projects/${m}/photos`).then(h);l.useEffect(()=>{x(),d.get("/gallery-projects").then(e=>v(e.find(r=>String(r.id)===String(m))||null)).catch(()=>{})},[m]);const F=async e=>{const r=Array.from(e.target.files||[]);if(r.length===0)return;j(""),w(!0);let a=u.reduce((o,i)=>Math.max(o,Number(i.sort_order)||0),0),n=0;const g=[];for(let o=0;o<r.length;o++){y(`Foto ${o+1} von ${r.length} wird hochgeladen…`);try{const i=await L(r[o]);if(i.size>A)throw new Error(`zu groß (${I(i.size)}, max. 5 MB)`);const k=new FormData;k.append("file",i);const E=await d.post("/uploads",k);a+=10,await d.post("/gallery-photos",{gallery_project_id:Number(m),image_path:E.path,sort_order:a}),n++}catch(i){g.push(`${r[o].name}: ${i.message}`)}}w(!1),y(""),p.current&&(p.current.value=""),x(),g.length===0?s.success(n===1?"1 Foto hochgeladen.":`${n} Fotos hochgeladen.`):(j(`Nicht hochgeladen:
|
|
${g.join(`
|
|
`)}`),s.error(`${n} hochgeladen, ${g.length} fehlgeschlagen.`))},P=(e,r)=>{h(a=>a.map(n=>n.id===e.id?{...n,caption:r}:n))},N=l.useRef(null),S=async e=>{if((e.caption||"")!==N.current)try{await d.put(`/gallery-photos/${e.id}`,{caption:e.caption,sort_order:e.sort_order}),s.success("Bildunterschrift gespeichert.")}catch(r){s.error(`Speichern fehlgeschlagen: ${r.message}`)}},_=async e=>{if(confirm("Foto wirklich entfernen?"))try{await d.delete(`/gallery-photos/${e}`),s.success("Foto entfernt."),x()}catch(r){s.error(`Entfernen fehlgeschlagen: ${r.message}`)}},R=async e=>{const r=u;h(e);try{h(await D("gallery-photos",e)),s.success("Reihenfolge gespeichert.")}catch(a){h(r),s.error(`Reihenfolge konnte nicht gespeichert werden: ${a.message}`)}};return t.jsxs("div",{children:[t.jsx("p",{className:"mb-2 text-sm",children:t.jsx(C,{to:"/admin/gallery-projects",className:"text-brand-600 hover:underline",children:"← Zurück zu den Projekten"})}),t.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[t.jsxs("h1",{className:"text-xl font-bold text-neutral-900 dark:text-white",children:["Fotos im Projekt",c?`: ${c.brand_name} ${c.name}`:""]}),c&&t.jsx(G,{to:`/galerie/${c.brand_slug}/${c.slug}`})]}),t.jsxs("div",{className:"mb-6 rounded-xl border border-neutral-200 bg-white p-4 dark:border-neutral-800 dark:bg-neutral-900",children:[t.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:"Fotos hinzufügen (Mehrfachauswahl möglich)"}),t.jsx("input",{ref:p,type:"file",multiple:!0,accept:"image/png,image/jpeg,image/webp",onChange:F,disabled:b,className:"text-sm"}),t.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"JPG, PNG oder WebP, große Fotos werden automatisch verkleinert."}),b&&t.jsx("p",{className:"mt-2 text-sm text-neutral-500","aria-live":"polite",children:$})]}),f&&t.jsx("p",{className:"mb-4 whitespace-pre-line text-sm text-red-600",children:f}),u.length>1&&t.jsx("p",{className:"mb-3 text-xs text-neutral-500 dark:text-neutral-400",children:"Reihenfolge am Griff per Ziehen ändern."}),t.jsx(M,{items:u,onReorder:R,as:"grid",className:"grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4",children:(e,r)=>t.jsxs("div",{className:"overflow-hidden rounded-xl border border-neutral-200 bg-white dark:border-neutral-800 dark:bg-neutral-900",children:[t.jsx("img",{src:e.image_path,alt:e.caption||"",className:"aspect-square w-full object-cover",loading:"lazy"}),t.jsxs("div",{className:"space-y-2 p-3",children:[t.jsx("input",{value:e.caption||"",onChange:a=>P(e,a.target.value),onFocus:()=>{N.current=e.caption||""},onBlur:()=>S(e),placeholder:"Bildunterschrift (optional)",className:"w-full rounded-md border border-neutral-300 bg-white px-2 py-1 text-xs dark:border-neutral-700 dark:bg-neutral-900"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r,t.jsx("button",{onClick:()=>_(e.id),className:"text-xs text-red-600 hover:underline",children:"Entfernen"})]})]})]})}),u.length===0&&t.jsx("p",{className:"py-6 text-center text-neutral-400",children:"Noch keine Fotos in diesem Projekt."})]})}export{J as default};
|