+
diff --git a/src/components/Blogs/Blogs.tsx b/src/components/Blogs/Blogs.tsx
index 9088e3c..defda97 100644
--- a/src/components/Blogs/Blogs.tsx
+++ b/src/components/Blogs/Blogs.tsx
@@ -5,10 +5,11 @@ import { sanitizeBlogContentIntoStringPreview } from "@/utils/sanitize";
export interface BlogsProps {
page: number;
+ search?: string;
}
-export default async function Blogs({ page }: BlogsProps) {
- const data = await fetchBlog(page);
+export default async function Blogs({ page, search }: BlogsProps) {
+ const data = await fetchBlog(page, search);
if (!data?.totalDocs) return <>>;
diff --git a/src/components/Pagination.tsx b/src/components/Pagination.tsx
index 3aa5fef..b96701a 100644
--- a/src/components/Pagination.tsx
+++ b/src/components/Pagination.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useRouter } from "next/navigation";
+import { usePathname, useRouter } from "next/navigation";
import React from "react";
interface PaginationProps {
@@ -13,13 +13,18 @@ interface PaginationProps {
export default function Pagination({ page, hasPreviousPage, hasNextPage, totalPages }: PaginationProps) {
const activePage = page;
const router = useRouter();
+ const pathName = usePathname();
// Function to handle page change
const handlePageChange = (page: string | number) => {
if (typeof page === "string") return;
if (typeof window === "undefined") return;
- router.push(`/blog/?page=${page}`);
+ const url = new URL(window.location.href);
+ const searchParams = new URLSearchParams(url.search);
+ searchParams.set("page", `${page}`);
+
+ router.push(`${pathName}/?${searchParams}`);
};
const getPageNumbers = () => {
diff --git a/src/services/payload/blog.ts b/src/services/payload/blog.ts
index c5fd7a8..410c398 100644
--- a/src/services/payload/blog.ts
+++ b/src/services/payload/blog.ts
@@ -2,18 +2,33 @@ import payloadConfig from "@/payload.config";
import { formatDate } from "@/utils/datetime";
import { getPayload } from "payload";
-export async function fetchBlog(page: number | undefined) {
+export async function fetchBlog(page: number | undefined, search: string = "") {
const payload = await getPayload({ config: payloadConfig });
const blogDataQuery = await payload.find({
collection: "blogs",
page,
pagination: true,
limit: 6,
- where: {
- is_published: {
- equals: true,
- },
- },
+ where: !search
+ ? {
+ is_published: {
+ equals: true,
+ },
+ }
+ : {
+ and: [
+ {
+ is_published: {
+ equals: true,
+ },
+ },
+ {
+ title: {
+ contains: search,
+ },
+ },
+ ],
+ },
});
const formattedData = blogDataQuery.docs.map((item) => {
diff --git a/tailwind.config.ts b/tailwind.config.ts
index ecba4b4..e199f93 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -15,6 +15,8 @@ export default {
extColorPrimary2: "var(--ext-color-primary-2)",
extColorPrimary3: "var(--ext-color-primary-3)",
extColorPrimary4: "var(--ext-color-primary-4)",
+ extColorPrimary5: "var(--ext-color-primary-5)",
+ extColorPrimary6: "var(--ext-color-primary-6)",
},
},
},