-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathwithBlogCategories.tsx
More file actions
61 lines (53 loc) · 1.8 KB
/
withBlogCategories.tsx
File metadata and controls
61 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useTranslations } from 'next-intl';
import BlogPostCard from '#site/components/Blog/BlogPostCard';
import LinkTabs from '#site/components/Common/LinkTabs';
import Pagination from '#site/components/Common/Pagination';
import { mapAuthorToCardAuthors } from '#site/util/author';
import type { BlogPostsRSC } from '#site/types';
import type { ComponentProps, FC } from 'react';
type WithBlogCategoriesProps = {
categories: ComponentProps<typeof LinkTabs>['tabs'];
blogData: BlogPostsRSC & { category: string; page: number };
};
const mapPaginationPages = (category: string, pages: number) =>
[...Array(pages).keys()].map(page => ({
url: `/blog/${category}/page/${page + 1}`,
}));
const WithBlogCategories: FC<WithBlogCategoriesProps> = ({
categories,
blogData,
}) => {
const t = useTranslations();
return (
<>
<LinkTabs
label={t('layouts.blog.selectCategory')}
tabs={categories}
activeTab={blogData.category}
>
<div className="max-ml:grid-cols-[1fr] grid grid-cols-[repeat(auto-fill,minmax(--spacing(80),1fr))] [grid-gap:--spacing(12)_--spacing(8)]">
{blogData.posts.map(post => (
<BlogPostCard
key={post.slug}
title={post.title}
category={post.categories[0]}
authors={mapAuthorToCardAuthors(post.author)}
date={post.date}
slug={post.slug}
/>
))}
</div>
</LinkTabs>
<div className="mt-4 border-t border-t-neutral-200 pt-5 md:mt-8 dark:border-t-neutral-900">
<Pagination
currentPage={blogData.page}
pages={mapPaginationPages(
blogData.category,
blogData.pagination.pages
)}
/>
</div>
</>
);
};
export default WithBlogCategories;