Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2071-Side pagination #2236

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading