'use client';
import React, { useMemo, useState } from 'react';
import Link from 'next/link';
import {
BLOG_CATEGORIES,
type BlogArticle,
type BlogCategory,
} from '@/lib/blogDefaults';
function ArticleCard({
article,
featured,
}: {
article: BlogArticle;
featured?: boolean;
}) {
return (
{/* eslint-disable-next-line @next/next/no-img-element */}
{article.category}
{article.title}
{article.excerpt}
{article.author} · {article.date} · {article.readTime}
);
}
export function BlogListing({ articles }: { articles: BlogArticle[] }) {
const [category, setCategory] = useState<'All' | BlogCategory>('All');
const filtered = useMemo(
() =>
category === 'All'
? articles
: articles.filter((a) => a.category === category),
[articles, category]
);
const featured = filtered[0];
const rest = filtered.slice(1);
return (
News & Blog
Tech news, buying guides, and repair tips from the iFixKart team.
{BLOG_CATEGORIES.map((cat) => {
const active = category === cat;
return (
);
})}
{filtered.length === 0 ? (
No articles in this category yet.
) : (
<>
{featured ?
: null}
{rest.length > 0 ? (
{rest.map((article) => (
))}
) : null}
>
)}
);
}
export function BlogArticleView({
article,
related,
}: {
article: BlogArticle;
related: BlogArticle[];
}) {
return (
← All articles
{article.category}
{article.title}
By {article.author} · {article.date} · {article.readTime}
{/* eslint-disable-next-line @next/next/no-img-element */}
{article.body.map((para, i) => (
{para}
))}
{related.length > 0 ? (
More stories
{related.map((item) => (
))}
) : null}
);
}