"use client"; import { useRouter, useSearchParams, useParams, usePathname, } from "next/navigation"; import {useEffect, useState} from "react"; import Link from "next/link"; 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); const [error, setError] = useState(null); useEffect(() => { setTimeout(() => { setIsVisible(true); }, 150); // Delay to start the animation }, []); useEffect(() => { const projectData = searchParams.get("project"); if (projectData) { setProject(JSON.parse(projectData as string)); // Remove the project data from the URL without reloading the page if (typeof window !== "undefined") { 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; try { fetchProjectData(slug); } catch (error) { console.log(error); setError("Failed to fetch project data"); } } }, [searchParams, router, params, pathname]); const fetchProjectData = async (slug: string) => { try { const response = await fetch(`/api/fetchProject?slug=${slug}`); if (!response.ok) { setError("Failed to fetch project Data"); } const projectData = (await response.json()) as { posts: Project[] }; if (projectData.posts.length === 0) { setError("Project not found"); } setProject(projectData.posts[0]); } catch (error) { console.error("Failed to fetch project data:", error); setError("Project not found"); } }; if (error) { return (

404

{error}

Go Back Home
); } if (!project) { return (
); } const featureImageUrl = project.feature_image ? `/api/fetchImage?url=${encodeURIComponent(project.feature_image)}` : ""; return (
{featureImageUrl && (
{project.title}
)}

{project.title}

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