Textmengencheck: Ausrichtungs-Dropdown (hoch/quer) + robustes Laden
All checks were successful
Build & Deploy / deploy (push) Successful in 23s

Formate werden zu Familien (family) gruppiert; hat eine Familie mehrere
Ausrichtungen (orientation hoch/quer), erscheint ein zweites Dropdown.
fetchCheckFormats faellt auf aktive Formate zurueck, falls show_check
(vor dem Directus-Bootstrap) noch fehlt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
s4luorth
2026-09-30 11:04:37 +02:00
parent ffb4de7fba
commit ffef7a50de
2 changed files with 88 additions and 17 deletions

View File

@@ -232,7 +232,13 @@ export type Product = {
input_mode: 'text' | 'datei'; input_mode: 'text' | 'datei';
}; };
export type Format = { id: number; key: string; name: string; product: number }; export type Format = {
id: number; key: string; name: string; product: number;
/** Familie fürs Ausrichtungs-Dropdown (z. B. A5, A6). Leer = eigener Eintrag. */
family?: string | null;
/** Ausrichtung innerhalb der Familie. Leer = keine Wahl. */
orientation?: 'hoch' | 'quer' | null;
};
/** /**
* Produkt-Schlüssel, die für den angemeldeten Kunden individuell freigeschaltet * Produkt-Schlüssel, die für den angemeldeten Kunden individuell freigeschaltet
@@ -274,11 +280,23 @@ export async function fetchFormats(): Promise<Format[]> {
* öffentlichen Konfigurator bestellbar sind. Adress-Postkarten sind ausgenommen. * öffentlichen Konfigurator bestellbar sind. Adress-Postkarten sind ausgenommen.
*/ */
export async function fetchCheckFormats(): Promise<Format[]> { export async function fetchCheckFormats(): Promise<Format[]> {
const felder = 'fields=id,key,name,product,family,orientation';
try {
const data = await request( const data = await request(
'/items/formats?fields=id,key,name,product&filter[show_check][_eq]=true&limit=-1', `/items/formats?${felder}&filter[show_check][_eq]=true&limit=-1`,
{ auth: false }, { auth: false },
); );
return data?.data ?? []; const rows: Format[] = data?.data ?? [];
if (rows.length) return rows;
} catch {
/* Feld show_check evtl. noch nicht angelegt → Fallback unten. */
}
// Fallback (z. B. vor dem Directus-Bootstrap): aktive Formate, damit der Check nutzbar bleibt.
const aktiv = await request(
`/items/formats?${felder}&filter[active][_eq]=true&limit=-1`,
{ auth: false },
);
return aktiv?.data ?? [];
} }
/* ── Preis & Bestellung (Extension skrift-orders) ─────────────────────────── */ /* ── Preis & Bestellung (Extension skrift-orders) ─────────────────────────── */

View File

@@ -87,7 +87,9 @@ function overflowMeldung(overflow?: PreviewOverflow[]) {
export default function Textmenge() { export default function Textmenge() {
const [formate, setFormate] = useState<Format[]>([]); const [formate, setFormate] = useState<Format[]>([]);
const [settings, setSettings] = useState<PublicSettings | null>(null); const [settings, setSettings] = useState<PublicSettings | null>(null);
const [format, setFormat] = useState('a4'); // Format wird über Familie (A4/A5/A6/DIN lang) + optionale Ausrichtung (hoch/quer) gewählt.
const [familie, setFamilie] = useState('');
const [ausrichtung, setAusrichtung] = useState('');
const [font, setFont] = useState('tilda'); const [font, setFont] = useState('tilda');
const [realistic, setRealistic] = useState(true); const [realistic, setRealistic] = useState(true);
const [text, setText] = useState(''); const [text, setText] = useState('');
@@ -99,15 +101,45 @@ export default function Textmenge() {
const [gross, setGross] = useState(false); const [gross, setGross] = useState(false);
useEffect(() => { useEffect(() => {
fetchCheckFormats() fetchCheckFormats().then(setFormate).catch(() => {});
.then((f) => {
setFormate(f);
setFormat(f.find((x) => x.key === 'a4')?.key ?? f[0]?.key ?? 'a4');
})
.catch(() => {});
fetchSettings().then(setSettings).catch(() => {}); fetchSettings().then(setSettings).catch(() => {});
}, []); }, []);
// Formate zu Familien gruppieren (gleiche family = ein Eintrag mit Ausrichtungen).
// Formate ohne family bilden je einen eigenen Eintrag (Label = Name).
const familien = useMemo(() => {
const map = new Map<string, Format[]>();
for (const f of formate) {
const label = (f.family && f.family.trim()) || f.name;
if (!map.has(label)) map.set(label, []);
map.get(label)!.push(f);
}
return [...map.entries()].map(([label, items]) => ({ label, items }));
}, [formate]);
// Aktuelle Familie + verfügbare Ausrichtungen + effektiv gewähltes Format.
const aktuelleFamilie = familien.find((fm) => fm.label === familie) ?? familien[0] ?? null;
const ausrichtungen = (aktuelleFamilie?.items ?? []).filter((f) => f.orientation);
const hatAusrichtung = ausrichtungen.length > 1;
const gewaehltesFormat = aktuelleFamilie
? (hatAusrichtung
? (aktuelleFamilie.items.find((f) => f.orientation === ausrichtung) ?? aktuelleFamilie.items[0])
: aktuelleFamilie.items[0])
: null;
const formatKey = gewaehltesFormat?.key ?? 'a4';
// Standardauswahl setzen / reparieren, wenn Formate geladen sind oder sich die Familie ändert.
useEffect(() => {
if (!familien.length) return;
const gueltig = familien.some((fm) => fm.label === familie);
if (!gueltig) {
const start = familien.find((fm) => fm.items.some((f) => f.key === 'a4')) ?? familien[0];
setFamilie(start.label);
const ori = start.items.filter((f) => f.orientation);
setAusrichtung(ori.length > 1 ? (ori[0].orientation ?? '') : '');
}
}, [familien, familie]);
// Escape schließt die Großansicht. // Escape schließt die Großansicht.
useEffect(() => { useEffect(() => {
if (!gross) return; if (!gross) return;
@@ -142,7 +174,7 @@ export default function Textmenge() {
setDoc(null); setDoc(null);
setFehler(null); setFehler(null);
setGross(false); setGross(false);
}, [text, font, format, realistic]); }, [text, font, formatKey, realistic]);
async function generieren() { async function generieren() {
if (!text.trim() || laedt) return; if (!text.trim() || laedt) return;
@@ -153,7 +185,7 @@ export default function Textmenge() {
client_id: clientId(), client_id: clientId(),
text, text,
font, font,
format, format: formatKey,
realistic, realistic,
entries: [{}], entries: [{}],
}); });
@@ -185,13 +217,34 @@ export default function Textmenge() {
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap' }}> <div style={{ display: 'flex', gap: 16, flexWrap: 'wrap' }}>
<label className="sk-field" style={{ flex: '1 1 200px' }}> <label className="sk-field" style={{ flex: '1 1 200px' }}>
<span className="sk-label">Format</span> <span className="sk-label">Format</span>
<select className="sk-input" value={format} onChange={(e) => setFormat(e.target.value)}> <select
{formate.length === 0 && <option value="a4">A4</option>} className="sk-input"
{formate.map((f) => ( value={aktuelleFamilie?.label ?? ''}
<option key={f.key} value={f.key}>{f.name}</option> onChange={(e) => {
setFamilie(e.target.value);
const fam = familien.find((fm) => fm.label === e.target.value);
const ori = (fam?.items ?? []).filter((f) => f.orientation);
setAusrichtung(ori.length > 1 ? (ori[0].orientation ?? '') : '');
}}
>
{familien.length === 0 && <option value="">A4</option>}
{familien.map((fm) => (
<option key={fm.label} value={fm.label}>{fm.label}</option>
))} ))}
</select> </select>
</label> </label>
{hatAusrichtung && (
<label className="sk-field" style={{ flex: '1 1 200px' }}>
<span className="sk-label">Ausrichtung</span>
<select className="sk-input" value={ausrichtung} onChange={(e) => setAusrichtung(e.target.value)}>
{ausrichtungen.map((f) => (
<option key={f.key} value={f.orientation ?? ''}>
{f.orientation === 'hoch' ? 'Hochformat' : f.orientation === 'quer' ? 'Querformat' : f.name}
</option>
))}
</select>
</label>
)}
<label className="sk-field" style={{ flex: '1 1 200px' }}> <label className="sk-field" style={{ flex: '1 1 200px' }}>
<span className="sk-label">Schriftart</span> <span className="sk-label">Schriftart</span>
<select className="sk-input" value={font} onChange={(e) => setFont(e.target.value)}> <select className="sk-input" value={font} onChange={(e) => setFont(e.target.value)}>