|
| 1 | +import React, { useEffect, useState } from "react"; |
| 2 | +import { useParams, useNavigate } from "react-router-dom"; |
| 3 | +import { supabase } from "@/integrations/supabase/client"; |
| 4 | +import Navbar from "@/components/Navbar"; |
| 5 | +import Footer from "@/components/Footer"; |
| 6 | +import { Loader2 } from "lucide-react"; |
| 7 | + |
| 8 | +export default function ArchitectDetail() { |
| 9 | + const { id } = useParams<{ id: string }>(); |
| 10 | + const navigate = useNavigate(); |
| 11 | + const [architect, setArchitect] = useState<any>(null); |
| 12 | + const [loading, setLoading] = useState(true); |
| 13 | + |
| 14 | + useEffect(() => { |
| 15 | + const fetchArchitect = async () => { |
| 16 | + if (!id) return; |
| 17 | + |
| 18 | + setLoading(true); |
| 19 | + const { data, error } = await supabase |
| 20 | + .from("architects") |
| 21 | + .select("*") |
| 22 | + .eq("id", Number(id)) |
| 23 | + .single(); |
| 24 | + |
| 25 | + console.log("Supabase data:", data); |
| 26 | + console.log("Supabase error:", error); |
| 27 | + |
| 28 | + if (error) { |
| 29 | + console.error("Error fetching architect:", error); |
| 30 | + } else { |
| 31 | + setArchitect(data); |
| 32 | + } |
| 33 | + setLoading(false); |
| 34 | + }; |
| 35 | + |
| 36 | + fetchArchitect(); |
| 37 | + }, [id]); |
| 38 | + |
| 39 | + if (loading) { |
| 40 | + return ( |
| 41 | + <div className="flex items-center justify-center h-screen"> |
| 42 | + <Loader2 className="animate-spin w-8 h-8 text-gray-600" /> |
| 43 | + </div> |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + if (!architect) { |
| 48 | + return ( |
| 49 | + <div className="min-h-screen flex flex-col items-center justify-center text-center"> |
| 50 | + <p className="text-lg text-gray-600 mb-4">Architect not found 😢</p> |
| 51 | + <button |
| 52 | + onClick={() => navigate(-1)} |
| 53 | + className="px-6 py-3 bg-purple-600 text-white rounded-lg hover:bg-purple-700" |
| 54 | + > |
| 55 | + Go Back |
| 56 | + </button> |
| 57 | + </div> |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + return ( |
| 62 | + <div className="bg-white min-h-screen font-sans"> |
| 63 | + <Navbar /> |
| 64 | + |
| 65 | + <div className="max-w-5xl mx-auto p-6 mt-10"> |
| 66 | + <h1 className="text-4xl font-bold mb-4 text-center text-purple-700"> |
| 67 | + {architect.name} |
| 68 | + </h1> |
| 69 | + <p className="text-center text-gray-600 mb-8 text-lg"> |
| 70 | + {architect.specialization || "Architecture Expert"} |
| 71 | + </p> |
| 72 | + |
| 73 | + <div className="flex justify-center mb-8"> |
| 74 | + <img |
| 75 | + src={architect.image_url || "/placeholder-architect.jpg"} |
| 76 | + alt={architect.name} |
| 77 | + className="w-full sm:w-2/3 rounded-2xl shadow-lg" |
| 78 | + /> |
| 79 | + </div> |
| 80 | + |
| 81 | + <p className="text-gray-700 leading-relaxed text-center text-lg"> |
| 82 | + {architect.description || "No additional details available."} |
| 83 | + </p> |
| 84 | + </div> |
| 85 | + |
| 86 | + <Footer /> |
| 87 | + </div> |
| 88 | + ); |
| 89 | +} |
0 commit comments