Commit 1ab8e591 by Madhankumar

code changes in bloglist

parent 45a48db0
......@@ -17,16 +17,6 @@ async function fetchBlogsByTitle(pageNo, search) {
console.log(er.message);
}
}
async function fetchBlogs(pageNo) {
try {
const response = await getPosts("posts", pageNo);
return response;
} catch (err) {
console.log(err.message);
}
}
const Home = async ({ searchParams }) => {
let blogs = [];
let blogsLength = 0;
......@@ -34,15 +24,19 @@ const Home = async ({ searchParams }) => {
let search = searchParams.search || "";
let response;
if (!search) {
const { data, total } = await fetchBlogs(pageNo);
response = { data, total: total };
try {
const { data, total } = await getPosts("posts", pageNo);
response = { data, total: total };
} catch (err) {
console.log(err.message);
}
} else {
response = await fetchBlogsByTitle(pageNo, search);
}
blogs = response.data;
blogsLength = response.total;
pageNo = blogsLength > 6 ? pageNo : 1;
pageNo = blogsLength > 6 ? pageNo : 1; // if length goes greater than 6 then take pagenum otherwise 1
return (
<div className={styles.container}>
......
......@@ -26,7 +26,7 @@ const BlogLists = ({
const handlePageChange = (pageNumber) => {
redirect(pageNumber);
window.scrollTo({ top: 0, behavior: "smooth" });
// window.scrollTo({ top: 0, behavior: "smooth" });
};
return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment