From 067e847524f8ba8fab879087e45214edff2ad735 Mon Sep 17 00:00:00 2001 From: Peter Meier Date: Wed, 13 May 2026 09:25:00 +0200 Subject: [PATCH] feat(windkarte): wind_map referenziert wind_area explizit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit areas-Feld im Schema + Block-Logik: referenzierte Slugs werden einzeln gefetcht. Leer = alle published areas als Fallback. Ermöglicht verschiedene Karten-Blöcke mit unterschiedlichen Gebiet-Subsets. Co-Authored-By: Claude Sonnet 4.6 --- src/lib/block-types.ts | 2 ++ .../components/blocks/WindkarteBlock.svelte | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/lib/block-types.ts b/src/lib/block-types.ts index 36ccb12..7f09f5a 100644 --- a/src/lib/block-types.ts +++ b/src/lib/block-types.ts @@ -428,4 +428,6 @@ export interface WindMapBlockData { name?: string; title?: string; subtitle?: string; + /** Explizite Auswahl von wind_area-Slugs. Leer/null = alle published areas. */ + areas?: (string | { _slug: string;[key: string]: unknown })[]; } diff --git a/src/lib/components/blocks/WindkarteBlock.svelte b/src/lib/components/blocks/WindkarteBlock.svelte index a4435ea..bdd96bf 100644 --- a/src/lib/components/blocks/WindkarteBlock.svelte +++ b/src/lib/components/blocks/WindkarteBlock.svelte @@ -25,12 +25,29 @@ onMount(async () => { try { - const res = await fetch(`${CMS_BASE}/api/content/wind_area?limit=100`, { - signal: AbortSignal.timeout(6_000), - }); - if (res.ok) { - const data = await res.json(); - areas = data.items ?? []; + const slugs = (block.areas ?? []) + .map((a) => (typeof a === "string" ? a : a._slug)) + .filter(Boolean); + + if (slugs.length > 0) { + // Fetch only the explicitly referenced areas in parallel + const results = await Promise.all( + slugs.map((slug) => + fetch(`${CMS_BASE}/api/content/wind_area/${slug}`, { + signal: AbortSignal.timeout(6_000), + }).then((r) => (r.ok ? r.json() : null)) + ) + ); + areas = results.filter((r): r is WindArea => r !== null); + } else { + // Fallback: all published areas + const res = await fetch(`${CMS_BASE}/api/content/wind_area?limit=100`, { + signal: AbortSignal.timeout(6_000), + }); + if (res.ok) { + const data = await res.json(); + areas = data.items ?? []; + } } } catch { // Map renders without CMS metadata — GeoJSON tooltips still work