diff --git a/src/app/(routes)/blog/categories/[categorySlug]/page.tsx b/src/app/(routes)/blog/categories/[categorySlug]/page.tsx index 60a9cc6..d6ef392 100644 --- a/src/app/(routes)/blog/categories/[categorySlug]/page.tsx +++ b/src/app/(routes)/blog/categories/[categorySlug]/page.tsx @@ -2,12 +2,15 @@ import { CategoryDataType, categorySlugPropsType } from "@/app/types/types"; import Image from "next/image"; import Link from "next/link"; import { redirect } from "next/navigation"; +import NoDataFounded from "../../components/no-data-founded/noDataFounded"; +import Pagination from "../../components/pagination/pagination"; export default async function SingleCategory({ params, + searchParams, }: categorySlugPropsType) { const categoryData: CategoryDataType = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/blog/categories/${params.categorySlug}/posts`, + `${process.env.NEXT_PUBLIC_API_URL}/blog/categories/${params.categorySlug}/posts?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`, { cache: "no-store", }, @@ -42,47 +45,54 @@ export default async function SingleCategory({
  • -

    + categories -

    + -
  • -

    +

    {categoryData.category.name} + + {categoryData.meta.total} +

  • - {categoryData.posts.map((post) => ( -
    - {`${post.title} -
    -
    -

    - BY -

    - - {post.author.name} - -
    - {/*
    + {categoryData.posts.length > 0 ? ( + categoryData.posts.map((post) => ( +
    + {`${post.title} +
    +
    +

    + BY +

    + + {post.author.name} + +
    + {/*

    IN

    @@ -93,19 +103,28 @@ export default async function SingleCategory({ {post.category.name}
    */} +
    + + {post.title} + +

    + {post.excerpt} +

    - - {post.title} - -

    - {post.excerpt} -

    -
    - ))} + )) + ) : ( + + )}
    + {categoryData.posts.length > 0 && categoryData.meta.last_page > 1 && ( + + )}
    ); diff --git a/src/app/(routes)/blog/categories/page.tsx b/src/app/(routes)/blog/categories/page.tsx index 22e0d6b..1693e74 100644 --- a/src/app/(routes)/blog/categories/page.tsx +++ b/src/app/(routes)/blog/categories/page.tsx @@ -46,8 +46,11 @@ export default async function Categories({
  • -

    +

    categories + + {CategoriesData.meta.total} +

  • @@ -86,7 +89,7 @@ export default async function Categories({ {CategoriesData.data.length > 0 && CategoriesData.meta.last_page > 1 && ( - + )} diff --git a/src/app/(routes)/blog/components/pagination/pagination.tsx b/src/app/(routes)/blog/components/pagination/pagination.tsx index 178336a..f771422 100644 --- a/src/app/(routes)/blog/components/pagination/pagination.tsx +++ b/src/app/(routes)/blog/components/pagination/pagination.tsx @@ -13,9 +13,10 @@ interface Meta { interface PaginationProps { meta: Meta; + baseUrl: string; // اضافه کردن prop برای base URL } -const Pagination: React.FC = ({ meta }) => { +const Pagination: React.FC = ({ meta, baseUrl }) => { const { current_page, last_page, total } = meta; const searchParams = useSearchParams(); @@ -27,7 +28,7 @@ const Pagination: React.FC = ({ meta }) => { const generatePageLink = (page: number): string => { const params = new URLSearchParams(searchParams.toString()); params.set("page", page.toString()); - return `/blog/categories?${params.toString()}`; + return `${baseUrl}?${params.toString()}`; // استفاده از baseUrl }; const renderPageNumbers = (): (JSX.Element | string)[] => { diff --git a/src/app/types/types.ts b/src/app/types/types.ts index 6167afb..a1d18a3 100644 --- a/src/app/types/types.ts +++ b/src/app/types/types.ts @@ -54,6 +54,7 @@ export type PostType = { export type categorySlugPropsType = { params: { categorySlug: string }; + searchParams: any; }; export type categoryPropsType = { @@ -73,7 +74,8 @@ export type PaginationType = { export type CategoryDataType = { category: CategoryType; posts: PostType[]; - pagination: PaginationType; + meta: any; + links: any; }; export type FilteredPostsPagepropsType = {