Gefixt: Objekt-Namen werden jetzt für Galerie/Share normalisiert, damit React keine Objekte mehr rendern muss.
Änderungen:
- resources/js/guest/services/galleryApi.ts: Locale-Felder (event.name, event.description) werden nach dem Fetch per coerceLocalized
in Strings überführt.
- resources/js/guest/services/photosApi.ts: fetchPhotoShare normalisiert event.name auf einen String mit de/en-Fallback; Fehler bei
fehlendem Share unverändert.
This commit is contained in:
@@ -59,6 +59,29 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
||||
return data as T;
|
||||
}
|
||||
|
||||
function coerceLocalized(value: unknown, fallback: string): string {
|
||||
if (typeof value === 'string' && value.trim() !== '') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value && typeof value === 'object') {
|
||||
const obj = value as Record<string, unknown>;
|
||||
const preferred = ['de', 'en'];
|
||||
for (const key of preferred) {
|
||||
const candidate = obj[key];
|
||||
if (typeof candidate === 'string' && candidate.trim() !== '') {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
const firstString = Object.values(obj).find((candidate) => typeof candidate === 'string' && candidate.trim() !== '');
|
||||
if (typeof firstString === 'string') {
|
||||
return firstString;
|
||||
}
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export async function fetchGalleryMeta(token: string, locale?: LocaleCode): Promise<GalleryMetaResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (locale) params.set('locale', locale);
|
||||
@@ -70,7 +93,17 @@ export async function fetchGalleryMeta(token: string, locale?: LocaleCode): Prom
|
||||
credentials: 'omit',
|
||||
});
|
||||
|
||||
return handleResponse<GalleryMetaResponse>(response);
|
||||
const data = await handleResponse<GalleryMetaResponse>(response);
|
||||
|
||||
if (data?.event) {
|
||||
data.event = {
|
||||
...data.event,
|
||||
name: coerceLocalized((data.event as any).name, 'Fotospiel Event'),
|
||||
description: coerceLocalized((data.event as any).description, ''),
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchGalleryPhotos(token: string, cursor?: string | null, limit = 30): Promise<GalleryPhotosResponse> {
|
||||
|
||||
@@ -251,5 +251,35 @@ export async function fetchPhotoShare(slug: string) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.json();
|
||||
const payload = await res.json();
|
||||
|
||||
const normalize = (value: unknown, fallback: string): string => {
|
||||
if (typeof value === 'string' && value.trim() !== '') {
|
||||
return value;
|
||||
}
|
||||
if (value && typeof value === 'object') {
|
||||
const obj = value as Record<string, unknown>;
|
||||
const preferred = ['de', 'en'];
|
||||
for (const key of preferred) {
|
||||
const candidate = obj[key];
|
||||
if (typeof candidate === 'string' && candidate.trim() !== '') {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
const firstString = Object.values(obj).find((candidate) => typeof candidate === 'string' && candidate.trim() !== '');
|
||||
if (typeof firstString === 'string') {
|
||||
return firstString;
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
};
|
||||
|
||||
if (payload?.event) {
|
||||
payload.event = {
|
||||
...payload.event,
|
||||
name: normalize(payload.event?.name, 'Fotospiel Event'),
|
||||
};
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user