"use client"; import { useRouter, useSearchParams, useParams, usePathname, } from "next/navigation"; import { useEffect, useState } from "react"; import Footer_Back from "@/app/components/Footer_Back"; import Header from "@/app/components/Header"; import Image from "next/image"; import "@/app/styles/ghostContent.css"; // Import the global styles interface Project { slug: string; id: string; title: string; feature_image: string; visibility: string; published_at: string; updated_at: string; html: string; reading_time: number; meta_description: string; } const ProjectDetails = () => { const router = useRouter(); const searchParams = useSearchParams(); const params = useParams(); const pathname = usePathname(); const [project, setProject] = useState(null); const [isVisible, setIsVisible] = useState(false); useEffect(() => { setTimeout(() => { setIsVisible(true); }, 150); // Delay to start the animation }, []); useEffect(() => { const projectData = searchParams.get("project"); if (projectData) { setProject(JSON.parse(projectData)); // Remove the project data from the URL without reloading the page const url = new URL(window.location.href); url.searchParams.delete("project"); window.history.replaceState({}, "", url.toString()); } else { // Fetch project data based on slug from URL const slug = params.slug as string; fetchProjectData(slug); } }, [searchParams, router, params, pathname]); const fetchProjectData = async (slug: string) => { try { const response = await fetch(`/api/fetchProject?slug=${slug}`); if (!response.ok) { throw new Error("Failed to fetch project data"); } const projectData = await response.json(); setProject(projectData.posts[0]); // Assuming the API returns an array of posts } catch (error) { console.error("Failed to fetch project data:", error); } }; if (!project) { return (
); } const featureImageUrl = `/api/fetchImage?url=${encodeURIComponent(project.feature_image)}`; return (
{/* Hero Section */}
{" "} {/* 16:9 Aspect Ratio */} {project.title}

{project.title}

{/* Project Content */}
); }; export default ProjectDetails;