"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import Image from "next/image"; import { ArrowLeft, Calendar, Clock, Share2, Bookmark, ChevronUp } from "lucide-react"; import { useQuery } from "@tanstack/react-query"; import { useParams } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { fetchBlogById } from "@/api/hub"; import type { Blog } from "@/types"; export default function BlogPage() { // Get the dynamic route parameter. const params = useParams(); const blogId = params.id as string; // Fetch the blog based on its id. const { data: blog, isLoading, isError, } = useQuery({ queryKey: ["blog", blogId], queryFn: () => fetchBlogById(blogId), staleTime: 60 * 1000, }); // Local state for the "scroll to top" button. const [showScrollTop, setShowScrollTop] = useState(false); useEffect(() => { const handleScroll = () => { setShowScrollTop(window.scrollY > 300); }; window.addEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll); }, []); const scrollToTop = () => { window.scrollTo({ top: 0, behavior: "smooth" }); }; const scrollToSection = (id: string) => { const element = document.getElementById(id); if (element) { element.scrollIntoView({ behavior: "smooth" }); } }; if (isLoading) { return
Loading...
; } if (isError || !blog) { return
Error loading blog.
; } return (
{/* Header */}

Share article

Save article

{/* Main content */}
{/* Article content */}
{blog.topic}

{blog.title}

{new Date(blog.date).toLocaleDateString()}
{blog.readTime}
By {blog.author}
{blog.title}

{blog.description}

{/* Sidebar */}
{/* Table of contents */}
{/**/} {/* */} {/* Table of Contents*/} {/* */} {/* */} {/* */} {/* */} {/**/} {/* Related articles */} {blog.relatedArticles && ( Related Articles
{blog.relatedArticles.map((article) => (
{article.title}

{article.title}

{article.topic}
))}
)}
{/* Scroll to top button */} {showScrollTop && ( )}
); }