From b8220e12ae17f1e0dd801ebd84c1bcd471257094 Mon Sep 17 00:00:00 2001 From: mpn <123456> Date: Sat, 6 Apr 2024 23:33:53 +0330 Subject: [PATCH] bug image torob and yektanet , page all product --- .../AppsComponent/CategoriesData/page.jsx | 10 +- components/AppsComponent/RootData/page.jsx | 2 + components/Category/FilterCategory/page.jsx | 6 +- components/Category/ListProdocts/page.jsx | 2 +- .../Mobile/FilterCategoryMobile/page.jsx | 4 +- .../Category/PaginationCategoory/page.jsx | 137 ++++++++++-------- plugins/Goftino/page.jsx | 17 ++- plugins/Yektanet/page.jsx | 19 +++ src/app/categories/page.jsx | 18 +++ src/app/products/[...id]/page.jsx | 5 +- 10 files changed, 143 insertions(+), 77 deletions(-) create mode 100644 plugins/Yektanet/page.jsx create mode 100644 src/app/categories/page.jsx diff --git a/components/AppsComponent/CategoriesData/page.jsx b/components/AppsComponent/CategoriesData/page.jsx index 9577b61..32fed5a 100644 --- a/components/AppsComponent/CategoriesData/page.jsx +++ b/components/AppsComponent/CategoriesData/page.jsx @@ -28,7 +28,9 @@ export default function CategoriesData({ params }) { const fetchBarnds = async () => { const res = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/brand?categoryId=${params.id[0]}` + `${process.env.NEXT_PUBLIC_API_URL}/brand${ + params.id[0] != 0 ? `?categoryId=${params.id[0]}` : "" + }` ); const brands = await res.json(); CTX.setBrands(brands); @@ -43,12 +45,12 @@ export default function CategoriesData({ params }) { // Fetch products for the next page CTX.fetchProducts( nextPage, - params.id[0], + params.id[0] != 0 ? params.id[0] : "", selectedBrands, isChecked, rangePrice, rangePrice, - sortBy, + sortBy != -1 ? sortBy : "", isRangePrice ); @@ -60,7 +62,7 @@ export default function CategoriesData({ params }) { top: 0, behavior: "smooth", // Optional: smooth scrolling behavior }); - CTX.fetchProducts(0, params.id[0]); + CTX.fetchProducts(0, params.id[0] != 0 ? params.id[0] : ""); fetchBarnds(); }, []); diff --git a/components/AppsComponent/RootData/page.jsx b/components/AppsComponent/RootData/page.jsx index 89ca48e..76935e9 100644 --- a/components/AppsComponent/RootData/page.jsx +++ b/components/AppsComponent/RootData/page.jsx @@ -16,6 +16,7 @@ import "../../../style/globals.css"; import Goftino from "plugins/Goftino/page"; import { useRouter } from "next/navigation"; import NextTopLoader from "nextjs-toploader"; +import Yektanet from "plugins/Goftino/page"; const RootData = ({ children }) => { const [cart, setCart] = useState([]); @@ -494,6 +495,7 @@ const RootData = ({ children }) => { /> + ); }; diff --git a/components/Category/FilterCategory/page.jsx b/components/Category/FilterCategory/page.jsx index 1d4e338..d159e8b 100644 --- a/components/Category/FilterCategory/page.jsx +++ b/components/Category/FilterCategory/page.jsx @@ -55,7 +55,7 @@ const FilterCategory = ({ isChecked, rangePrice[0], rangePrice[1], - sortBy, + sortBy != -1 ? sortBy : "", isRangePrice ); }; @@ -68,12 +68,12 @@ const FilterCategory = ({ CTX.fetchProducts( 0, - id[0], + id[0] != 0 ? id[0] : "", selectedBrands, isChecked, rangePrice[0], rangePrice[1], - sortBy, + sortBy != -1 ? sortBy : "", isRangePrice ); }, [CTX.state.selectedBrands, CTX.state.isChecked]); diff --git a/components/Category/ListProdocts/page.jsx b/components/Category/ListProdocts/page.jsx index 205f563..8cf3c8c 100644 --- a/components/Category/ListProdocts/page.jsx +++ b/components/Category/ListProdocts/page.jsx @@ -34,7 +34,7 @@ const ListProdocts = ({ isChecked, rangePrice, rangePrice, - sortBy, + sortBy != -1 ? sortBy : "", isRangePrice ); } diff --git a/components/Category/Mobile/FilterCategoryMobile/page.jsx b/components/Category/Mobile/FilterCategoryMobile/page.jsx index 4b7bd66..5a8fae2 100644 --- a/components/Category/Mobile/FilterCategoryMobile/page.jsx +++ b/components/Category/Mobile/FilterCategoryMobile/page.jsx @@ -13,12 +13,12 @@ const FilterCategoryMobile = (props) => { if (props.sortBy != -1) { CTX.fetchProducts( 0, - props.id[0], + props.id[0] != 0 ? props.id[0] : "", props.selectedBrands, props.isChecked, props.rangePrice, props.rangePrice, - props.sortBy, + props.sortBy != -1 ? props.sortBy : "", props.isRangePrice ); } diff --git a/components/Category/PaginationCategoory/page.jsx b/components/Category/PaginationCategoory/page.jsx index bf2aa37..cb5cf5a 100644 --- a/components/Category/PaginationCategoory/page.jsx +++ b/components/Category/PaginationCategoory/page.jsx @@ -10,78 +10,95 @@ const PaginationCategoory = (props) => { const pageGetProducts = CTX.state.pageGetProducts; const [currentPageIndex, setCurrentPageIndex] = useState(pageGetProducts); + const renderPaginationButtons = () => { const buttons = []; - for (let i = 0; i < pager?.totalPage; i++) { - buttons.push( -
{ - console.log("ss", i); - setCurrentPageIndex(i); - CTX.fetchProducts( - i, - props.id[0], - props.selectedBrands, - props.isChecked, - props.rangePrice, - props.rangePrice, - props.sortBy, - props.isRangePrice, - true //pagination say or not - ); - }} - > -

- -

-
- ); + const totalPages = pager?.totalPage; + const maxButtonsToShow = 7; // Maximum buttons to show + + // If total pages are greater than maxButtonsToShow + if (totalPages > maxButtonsToShow) { + // Show buttons for the first page + buttons.push(renderPageButton(0)); + + // If current page is not too close to the start, show ellipsis + if (currentPageIndex > 2) { + buttons.push(renderEllipsis()); + } + + // Calculate the start index for buttons + const start = Math.max(1, currentPageIndex - 2); + + // Calculate the end index for buttons + const end = Math.min(currentPageIndex + 3, totalPages - 1); + + // Show buttons for pages within range + for (let i = start; i <= end; i++) { + buttons.push(renderPageButton(i)); + } + + // If current page is not too close to the end, show ellipsis + if (currentPageIndex < totalPages - 4) { + buttons.push(renderEllipsis()); + } + + // Show button for the last page + buttons.push(renderPageButton(totalPages - 1)); + } else { + // Show buttons for all pages + for (let i = 0; i < totalPages; i++) { + buttons.push(renderPageButton(i)); + } } + return buttons; }; + const renderPageButton = (pageIndex) => ( +
handlePageClick(pageIndex)} + > +

+ +

+
+ ); + + const renderEllipsis = () => ( +
+ ... +
+ ); + + const handlePageClick = (pageIndex) => { + setCurrentPageIndex(pageIndex); + // console.log("ss", i); + CTX.fetchProducts( + pageIndex, + props.id[0] != 0 ? props.id[0] : "", + props.selectedBrands, + props.isChecked, + props.rangePrice, + props.rangePrice, + props.sortBy != -1 ? props.sortBy : "", + props.isRangePrice, + true //pagination say or not + ); + // Your fetchProducts function call here + }; + return (
- - - + {/* Previous page button */}
{renderPaginationButtons()}
- - - + {/* Next page button */}
); diff --git a/plugins/Goftino/page.jsx b/plugins/Goftino/page.jsx index 317ea72..8e780b7 100644 --- a/plugins/Goftino/page.jsx +++ b/plugins/Goftino/page.jsx @@ -1,9 +1,18 @@ import Script from "next/script"; -export default function Goftino() { - const getGoftiono = () => { +export default function Yektanet() { + const getYektanet = () => { return { - __html: ` !function(){var i="Gk1Yld",a=window,d=document;function g(){var g=d.createElement("script"),s="https://www.goftino.com/widget/"+i,l=localStorage.getItem("goftino_"+i);g.async=!0,g.src=l?s+"?o="+l:s;d.getElementsByTagName("head")[0].appendChild(g);}"complete"===d.readyState?g():a.attachEvent?a.attachEvent("onload",g):a.addEventListener("load",g,!1);}(); + __html: ` !function (t, e, n) { + t.yektanetAnalyticsObject = n, t[n] = t[n] || function () { + t[n].q.push(arguments) + }, t[n].q = t[n].q || []; + var a = new Date, r = a.getFullYear().toString() + "0" + a.getMonth() + "0" + a.getDate() + "0" + a.getHours(), + c = e.getElementsByTagName("script")[0], s = e.createElement("script"); + s.id = "ua-script-rqSC1axy"; s.dataset.analyticsobject = n; + s.async = 1; s.type = "text/javascript"; + s.src = "https://cdn.yektanet.com/rg_woebegone/scripts_v3/rqSC1axy/rg.complete.js?v=" + r, c.parentNode.insertBefore(s, c) + }(window, document, "yektanet"); `, }; }; @@ -12,7 +21,7 @@ export default function Goftino() { <>