Files
d43d80a6-78e0-4910-bc33-a92…/src/app/blog/page.tsx

159 lines
8.7 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleMinimal from '@/components/navbar/NavbarStyleMinimal';
import FooterCard from "@/components/sections/footer/FooterCard";
import { Twitter, Linkedin, Github } from 'lucide-react';
type BlogPost = {
id: string;
category: string;
title: string;
excerpt: string;
imageSrc: string;
imageAlt?: string;
authorName: string;
authorAvatar: string;
date: string;
onBlogClick?: () => void;
};
const defaultPosts: BlogPost[] = [
{
id: "1", category: "Design", title: "UX review presentations", excerpt: "How do you create compelling presentations that wow your colleagues and impress your managers?", imageSrc: "/placeholders/placeholder3.avif", imageAlt: "Abstract design with purple and silver tones", authorName: "Olivia Rhye", authorAvatar: "/placeholders/placeholder3.avif", date: "20 Jan 2025", onBlogClick: () => console.log("Blog 1 clicked"),
},
{
id: "2", category: "Development", title: "Building scalable applications", excerpt: "Learn the best practices for building applications that can handle millions of users.", imageSrc: "/placeholders/placeholder4.webp", imageAlt: "Development workspace", authorName: "John Smith", authorAvatar: "/placeholders/placeholder4.webp", date: "18 Jan 2025", onBlogClick: () => console.log("Blog 2 clicked"),
},
{
id: "3", category: "Marketing", title: "Content strategy essentials", excerpt: "Discover how to create a content strategy that drives engagement and conversions.", imageSrc: "/placeholders/placeholder3.avif", imageAlt: "Marketing strategy board", authorName: "Sarah Johnson", authorAvatar: "/placeholders/placeholder3.avif", date: "15 Jan 2025", onBlogClick: () => console.log("Blog 3 clicked"),
},
{
id: "4", category: "Product", title: "Product management 101", excerpt: "Everything you need to know to become an effective product manager in 2025.", imageSrc: "/placeholders/placeholder4.webp", imageAlt: "Product planning session", authorName: "Mike Davis", authorAvatar: "/placeholders/placeholder4.webp", date: "12 Jan 2025", onBlogClick: () => console.log("Blog 4 clicked"),
},
];
export default function BlogPage() {
const [posts, setPosts] = useState<BlogPost[]>(defaultPosts);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const fetchPosts = async () => {
try {
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;
if (!apiUrl || !projectId) {
console.warn("NEXT_PUBLIC_API_URL or NEXT_PUBLIC_PROJECT_ID not configured, using default posts");
setIsLoading(false);
return;
}
const url = `${apiUrl}/posts/${projectId}?status=published`;
const response = await fetch(url, {
method: "GET", headers: {
"Content-Type": "application/json"
},
});
if (response.ok) {
const resp = await response.json();
const data = resp.data;
if (Array.isArray(data) && data.length > 0) {
const mappedPosts = data.map((post: any) => ({
id: post.id || String(Math.random()),
category: post.category || "General", title: post.title || "Untitled", excerpt: post.excerpt || post.content.slice(0, 30) || "", imageSrc: post.imageUrl || "/placeholders/placeholder3.avif", imageAlt: post.imageAlt || post.title || "", authorName: post.author?.name || "Anonymous", authorAvatar: post.author?.avatar || "/placeholders/placeholder3.avif", date: post.date || post.createdAt || new Date().toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" }),
onBlogClick: () => console.log(`Blog ${post.id} clicked`),
}));
setPosts(mappedPosts);
}
} else {
console.warn(`API request failed with status ${response.status}, using default posts`);
}
} catch (error) {
console.error("Error fetching posts:", error);
} finally {
setIsLoading(false);
}
};
fetchPosts();
}, []);
return (
<ThemeProvider
defaultButtonVariant="elastic-effect"
defaultTextAnimation="background-highlight"
borderRadius="sharp"
contentWidth="compact"
sizing="largeSizeMediumTitles"
background="none"
cardStyle="gradient-mesh"
primaryButtonStyle="primary-glow"
secondaryButtonStyle="solid"
headingFontWeight="extrabold"
>
<ReactLenis root>
<div className="min-h-screen bg-background">
<NavbarStyleMinimal
brandName="Webild"
button={{
text: "Get Started", href: "#contact"
}}
/>
{isLoading ? (
<div className="w-content-width mx-auto py-20 text-center">
<p className="text-foreground">Loading posts...</p>
</div>
) : (
<div className="w-content-width mx-auto py-20">
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
{posts.map((post) => (
<div key={post.id} className="card p-6">
<div className="aspect-video mb-4 rounded-lg overflow-hidden">
<img src={post.imageSrc} alt={post.imageAlt} className="w-full h-full object-cover" />
</div>
<div className="mb-2">
<span className="text-sm text-accent font-medium">{post.category}</span>
</div>
<h2 className="text-xl font-semibold text-foreground mb-2">{post.title}</h2>
<p className="text-foreground/75 mb-4">{post.excerpt}</p>
<div className="flex items-center space-x-3">
<img src={post.authorAvatar} alt={post.authorName} className="w-8 h-8 rounded-full" />
<div className="flex flex-col">
<span className="text-sm font-medium text-foreground">{post.authorName}</span>
<span className="text-xs text-foreground/60">{post.date}</span>
</div>
</div>
</div>
))}
</div>
</div>
)}
<FooterCard
logoText="Webild"
copyrightText="© 2025 Webild. All rights reserved."
socialLinks={[
{
icon: Twitter,
href: "https://twitter.com", ariaLabel: "Twitter"
},
{
icon: Linkedin,
href: "https://linkedin.com", ariaLabel: "LinkedIn"
},
{
icon: Github,
href: "https://github.com", ariaLabel: "GitHub"
}
]}
/>
</div>
</ReactLenis>
</ThemeProvider>
);
}