Skip to content

Commit

Permalink
#2071-Side pagination (#2236)
Browse files Browse the repository at this point in the history
* Done the following changes

Signed-off-by: Raj <[email protected]>

* Minor changes in subcategory page

Signed-off-by: Raj <[email protected]>

* Fixed Errors

---------

Signed-off-by: Raj <[email protected]>
Co-authored-by: Raj <[email protected]>
  • Loading branch information
Raj100679 and Raj authored Jan 23, 2024
1 parent ff603f6 commit 229077d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
51 changes: 30 additions & 21 deletions components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
import React, { useEffect } from 'react';
import { useTheme } from 'next-themes';
import clsx from 'clsx';
import React, { useEffect } from 'react'
import { useTheme } from 'next-themes'
import clsx from 'clsx'

type PaginationProps = {
totalPages: number[] | null;
currentPage: number;
handlePageChange: (page: number) => void;
};
toporbottom: boolean
totalPages: number[] | null
currentPage: number
handlePageChange: (page: number) => void
}

export default function Pagination({
toporbottom,
totalPages,
currentPage,
handlePageChange,
}: PaginationProps) {
const { resolvedTheme } = useTheme();
const isDarkMode = resolvedTheme === 'dark';

const { resolvedTheme } = useTheme()
const isDarkMode = resolvedTheme === 'dark'
const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
window.scrollTo({ top: 0, behavior: 'smooth' })
}

const changePage = (page: number) => {
handlePageChange(page);
};
handlePageChange(page)
}

useEffect(() => {
scrollToTop();
}, [currentPage]);
scrollToTop()
}, [currentPage])

return (
<>
{totalPages && totalPages.length > 1 && (
<div
className={clsx(
'w-full z-20 flex lg:w-full items-center justify-center ',
'absolute bottom-2 right-0'
toporbottom == true
? 'w-full z-20 flex lg:w-full items-center justify-center absolute bottom-2 right-0'
: 'z-20 flex w-full lg:w-full items-center justify-end absolute top-0 right-0'
)}
>
<div className="flex items-center px-6 py-1 gap-4">
<div
className={clsx(
'flex items-center',
toporbottom == true ? 'px-6 py-1 gap-4' : 'gap-2'
)}
>
<button
className={clsx(
'flex items-center justify-center text-[#8b5cf6]',
Expand All @@ -57,7 +64,9 @@ export default function Pagination({
'flex items-center justify-center rounded-md hover:bg-[#8b5cf6] hover:text-white px-2',
currentPage === page
? 'bg-[#8b5cf6] text-white'
: isDarkMode ? 'text-light' : 'text-theme-secondary'
: isDarkMode
? 'text-light'
: 'text-theme-secondary'
)}
onClick={() => changePage(page)}
>
Expand All @@ -79,5 +88,5 @@ export default function Pagination({
</div>
)}
</>
);
)
}
12 changes: 10 additions & 2 deletions pages/[category]/[...subcategory].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const SubCategory: NextPage<PageProps> = ({ subcategory }) => {
} else {
content = <ComingSoon />
}
const toporbottom = true

return (
<>
Expand Down Expand Up @@ -101,8 +102,15 @@ const SubCategory: NextPage<PageProps> = ({ subcategory }) => {
className="relative min-h-[calc(100%-68px)] w-full pt-[85px] pb-4 md:min-h-[calc(100%-76px)] md:px-10 md:pt-10"
>
{content}
<div className="min-w-full h-10 py-5"/>
<Pagination
toporbottom={toporbottom}
totalPages={totalPages}
currentPage={currentPage}
handlePageChange={handlePageChange}
/>
<div className=" min-w-full h-10 py-5" />
<Pagination
toporbottom={!toporbottom}
totalPages={totalPages}
currentPage={currentPage}
handlePageChange={handlePageChange}
Expand Down Expand Up @@ -135,4 +143,4 @@ export const getStaticProps: GetStaticProps<PageProps, Params> = async (
}
}

export default SubCategory
export default SubCategory

1 comment on commit 229077d

@vercel
Copy link

@vercel vercel bot commented on 229077d Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.