|
1 | | -import ArticleCard from "../../src/components/ArticleCards/ArticleCard"; |
2 | | -import { SORTED_ARTICLES_BY_DATE } from "../../BLOG_CONSTANTS/_ARTICLES_LIST"; |
3 | | -import { useRouter } from "next/router"; |
4 | | -import { PageLayout } from "../../src/components"; |
5 | | -import { combineClasses } from "../../src/utils/utils"; |
6 | | -import ReactPaginate from "react-paginate"; |
7 | | -import { useEffect, useState } from "react"; |
8 | | -import { iArticle } from "../../src/shared/interfaces"; |
9 | | -import { AiFillCaretRight, AiFillCaretLeft } from "react-icons/ai"; |
| 1 | +import BlogIndexPage from "../../src/components/BlogIndexPage"; |
10 | 2 |
|
11 | | -const Categories = () => { |
12 | | - const router = useRouter(); |
13 | | - const { category, author } = router.query; |
14 | | - const categoryArticles = SORTED_ARTICLES_BY_DATE.filter( |
15 | | - (each) => each.preview.category === category |
16 | | - ); |
17 | | - const authorArticles = SORTED_ARTICLES_BY_DATE.filter( |
18 | | - (each) => each.preview.author.name === author |
19 | | - ); |
20 | | - const articles = category |
21 | | - ? categoryArticles |
22 | | - : author |
23 | | - ? authorArticles |
24 | | - : SORTED_ARTICLES_BY_DATE; |
25 | | - |
26 | | - const [currentItems, setCurrentItems] = useState([] || null); |
27 | | - const [pageCount, setPageCount] = useState(0); |
28 | | - const [itemOffset, setItemOffset] = useState(0); |
29 | | - const itemsPerPage = 6; |
30 | | - |
31 | | - useEffect(() => { |
32 | | - const endOffset = itemOffset + itemsPerPage; |
33 | | - setCurrentItems(articles.slice(itemOffset, endOffset) as any); |
34 | | - setPageCount(Math.ceil(articles.length / itemsPerPage)); |
35 | | - }, [itemOffset, itemsPerPage]); |
36 | | - |
37 | | - const handlePageClick = (event: any) => { |
38 | | - const newOffset = (event.selected * itemsPerPage) % articles.length; |
39 | | - setItemOffset(newOffset); |
40 | | - }; |
41 | | - |
42 | | - return ( |
43 | | - <PageLayout home> |
44 | | - <div |
45 | | - className={combineClasses( |
46 | | - "container mt-10 md:pt-0 px-0 md:px-3", |
47 | | - category ? "pt-10" : "pt-14" |
48 | | - )} |
49 | | - > |
50 | | - {category || author ? ( |
51 | | - <h1 |
52 | | - className="px-2 mb-[30px] text-[45px] font-bold" |
53 | | - style={{ textTransform: "capitalize" }} |
54 | | - > |
55 | | - {category || author} |
56 | | - <hr className="mt-[10px]" /> |
57 | | - </h1> |
58 | | - ) : null} |
59 | | - |
60 | | - <div className="flex flex-wrap"> |
61 | | - {currentItems |
62 | | - ? (currentItems as any).map((each: iArticle, i: any) => ( |
63 | | - <ArticleCard article={each.preview} path={each.path} key={i} /> |
64 | | - )) |
65 | | - : null} |
66 | | - </div> |
67 | | - |
68 | | - <ReactPaginate |
69 | | - breakLabel="..." |
70 | | - nextLabel={<AiFillCaretRight />} |
71 | | - onPageChange={handlePageClick} |
72 | | - pageRangeDisplayed={1} |
73 | | - pageCount={pageCount} |
74 | | - previousLabel={<AiFillCaretLeft />} |
75 | | - containerClassName="pagination" |
76 | | - activeClassName="active" |
77 | | - /> |
78 | | - </div> |
79 | | - </PageLayout> |
80 | | - ); |
| 3 | +const AllArticles = () => { |
| 4 | + return <BlogIndexPage articlesPerPage={6} />; |
81 | 5 | }; |
82 | 6 |
|
83 | | -export default Categories; |
| 7 | +export default AllArticles; |
0 commit comments