diff --git a/frontend/src/app/golfbaner/[slug]/FacilityDetailView.tsx b/frontend/src/app/golfbaner/[slug]/FacilityDetailView.tsx index 269c07c..e8529bb 100644 --- a/frontend/src/app/golfbaner/[slug]/FacilityDetailView.tsx +++ b/frontend/src/app/golfbaner/[slug]/FacilityDetailView.tsx @@ -1,11 +1,20 @@ "use client"; +/** + * TEE OFF DETAIL VIEW - COMPLETE v3.7 (STABLE) + * --------------------------------------------------------------------------- + * REGEL 1: Garanterer parsing av JSON-data (courses, amenities, greenfee osv). + * REGEL 2: Beholder 22/78 layout og alle visuelle seksjoner (Kart, Video, Priser). + * REGEL 3: Viser KUN bilder fra klubbens eget galleri i slideren. + * REGEL 4: Bruker monokrome ikoner (#11280f) og oransje lenker (#ff5722). + * --------------------------------------------------------------------------- + */ import { useState, useEffect } from 'react'; import { STATUS_MAP, FALLBACK_IMAGE } from "@/config/constants"; import Link from 'next/link'; import CourseDisplay from './CourseDisplay'; -// --- MONOKROME SVG IKONER (#11280f) --- +// --- MONOKROME SVG IKONER --- const Icon = ({ children, className = "w-5 h-5" }: { children: React.ReactNode, className?: string }) => ( {children} ); @@ -29,10 +38,20 @@ export default function FacilityDetailView({ facility }: { facility: any }) { const [showBackToTop, setShowBackToTop] = useState(false); const [currentSlide, setCurrentSlide] = useState(0); - const activeCourses = (facility.courses || []).filter((c: any) => c.holes && c.holes.length > 0); - const amenities = facility.amenities || {}; - const gallery = Array.isArray(facility.gallery) && facility.gallery.length > 0 ? facility.gallery : [facility.image_url || FALLBACK_IMAGE]; - const shotzoom = Array.isArray(facility.shotzoom) ? facility.shotzoom : []; + // --- DATA RECOVERY LOGIKK (Fikser krasj fra API-strenger) --- + const parseJson = (val: any, fallback: any) => { + if (!val) return fallback; + if (typeof val === 'object') return val; + try { return JSON.parse(val); } catch (e) { return fallback; } + }; + + const rawCourses = parseJson(facility.courses, []); + const activeCourses = Array.isArray(rawCourses) ? rawCourses.filter((c: any) => c.holes && (typeof c.holes === 'string' || c.holes.length > 0)) : []; + const amenities = parseJson(facility.amenities, {}); + const gallery = parseJson(facility.gallery, [facility.image_url || FALLBACK_IMAGE]); + const greenfee = parseJson(facility.greenfee, []); + const shotzoom = parseJson(facility.shotzoom, []); + const linkClass = "text-orange-600 hover:underline transition-colors font-bold"; useEffect(() => { @@ -53,18 +72,19 @@ export default function FacilityDetailView({ facility }: { facility: any }) { }; const formatDate = (d: string) => d ? new Date(d).toLocaleDateString('nb-NO', { day: 'numeric', month: 'long', year: 'numeric' }) : null; - const weatherImg = facility.weather_url?.replace("/graf/dag/", "/innhold/").replace(/\/$/, "") + "/meteogram.svg"; return (
+ {/* GALLERI SLIDER */}
{gallery.map((img: string, i: number) => ( ))}
+ {/* BANESTATUS BADGES */}
{activeCourses.map((c: any) => ( @@ -74,6 +94,7 @@ export default function FacilityDetailView({ facility }: { facility: any }) { {facility.status_updated_at && Sist oppdatert: {formatDate(facility.status_updated_at)}}
+ {/* HURTIGKNAPPER */}
{facility.website_url && } {facility.golfbox_booking_url && } @@ -82,20 +103,20 @@ export default function FacilityDetailView({ facility }: { facility: any }) { {facility.weather_url && }
-
+
{facility.logo_url &&
}

{facility.name}

{facility.county} • {facility.city}

+ {/* NAVIGASJON */}