Update src/app/blog/page.tsx
This commit is contained in:
@@ -20,6 +20,25 @@ type BlogPost = {
|
|||||||
onBlogClick?: () => void;
|
onBlogClick?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type BlogCard = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
author: string;
|
||||||
|
description: string;
|
||||||
|
tags: string[];
|
||||||
|
onBlogClick?: () => void;
|
||||||
|
} & ({
|
||||||
|
imageSrc: string;
|
||||||
|
imageAlt?: string;
|
||||||
|
videoSrc?: never;
|
||||||
|
videoAriaLabel?: never;
|
||||||
|
} | {
|
||||||
|
videoSrc: string;
|
||||||
|
videoAriaLabel?: string;
|
||||||
|
imageSrc?: never;
|
||||||
|
imageAlt?: never;
|
||||||
|
});
|
||||||
|
|
||||||
const defaultPosts: BlogPost[] = [
|
const defaultPosts: BlogPost[] = [
|
||||||
{
|
{
|
||||||
id: "1", title: "Helping Abandoned Pets Find Forever Homes", author: "Sarah Johnson", description: "Learn about our comprehensive adoption process and how we match pets with the perfect families.", tags: ["Adoption", "Success Stories"],
|
id: "1", title: "Helping Abandoned Pets Find Forever Homes", author: "Sarah Johnson", description: "Learn about our comprehensive adoption process and how we match pets with the perfect families.", tags: ["Adoption", "Success Stories"],
|
||||||
@@ -58,7 +77,8 @@ export default function BlogPage() {
|
|||||||
const url = `${apiUrl}/posts/${projectId}`;
|
const url = `${apiUrl}/posts/${projectId}`;
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "GET", headers: {
|
method: "GET", headers: {
|
||||||
"Content-Type": "application/json"},
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -84,6 +104,34 @@ export default function BlogPage() {
|
|||||||
fetchPosts();
|
fetchPosts();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Convert BlogPost[] to BlogCard[]
|
||||||
|
const convertToBlogCards = (blogPosts: BlogPost[]): BlogCard[] => {
|
||||||
|
return blogPosts.map(post => {
|
||||||
|
if (post.videoSrc) {
|
||||||
|
return {
|
||||||
|
id: post.id,
|
||||||
|
title: post.title,
|
||||||
|
author: post.author,
|
||||||
|
description: post.description,
|
||||||
|
tags: post.tags,
|
||||||
|
videoSrc: post.videoSrc,
|
||||||
|
videoAriaLabel: post.videoAriaLabel,
|
||||||
|
onBlogClick: post.onBlogClick
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
id: post.id,
|
||||||
|
title: post.title,
|
||||||
|
author: post.author,
|
||||||
|
description: post.description,
|
||||||
|
tags: post.tags,
|
||||||
|
imageSrc: post.imageSrc || "/placeholders/placeholder1.webp", imageAlt: post.imageAlt,
|
||||||
|
onBlogClick: post.onBlogClick
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider
|
<ThemeProvider
|
||||||
defaultButtonVariant="text-shift"
|
defaultButtonVariant="text-shift"
|
||||||
@@ -116,7 +164,7 @@ export default function BlogPage() {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<BlogCardEleven
|
<BlogCardEleven
|
||||||
blogs={posts}
|
blogs={convertToBlogCards(posts)}
|
||||||
animationType="slide-up"
|
animationType="slide-up"
|
||||||
title="Latest News & Stories"
|
title="Latest News & Stories"
|
||||||
description="Stay updated with our latest rescue stories, adoption successes, and animal care tips from the Happy Paws Shelter community."
|
description="Stay updated with our latest rescue stories, adoption successes, and animal care tips from the Happy Paws Shelter community."
|
||||||
|
|||||||
Reference in New Issue
Block a user