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

Feature/os 50 fe create pagination category page mob #74

Merged
merged 10 commits into from
Apr 12, 2024
23 changes: 23 additions & 0 deletions src/assets/svgs/ArrowLeft.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

const ArrowLeft = (): JSX.Element => {
return (
<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M19 22L13 16L19 10"
stroke="#212121"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
);
};

export default ArrowLeft;
23 changes: 23 additions & 0 deletions src/assets/svgs/ArrowLeftGrey.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

const ArrowLeftGrey = (): JSX.Element => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it the same icon as ArrowLeft?
please use ArrowLeft and change color

return (
<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M19 22L13 16L19 10"
stroke="#959595"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
);
};

export default ArrowLeftGrey;
23 changes: 23 additions & 0 deletions src/assets/svgs/ArrowRight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

const ArrowRight = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

return (
<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13 10L19 16L13 22"
stroke="#212121"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
);
};

export default ArrowRight;
23 changes: 23 additions & 0 deletions src/assets/svgs/ArrowRightGrey.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

const ArrowRightGrey = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

return (
<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13 10L19 16L13 22"
stroke="#959595"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
);
};

export default ArrowRightGrey;
4 changes: 2 additions & 2 deletions src/components/SameStyleAndVisitedProducts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useGetProductsByIdWithImagesQuery,
} from 'redux/productsApi';
import { BodySearchProducts } from 'redux/types';
import { FIRST_PAGE, SIMILAR_PRODUCTS_SIZE } from 'utils/constants';
import { PageNumbers, SIMILAR_PRODUCTS_SIZE } from 'utils/constants';
import ProductsGridShort from 'modules/product/components/ProductsGridShort';
import styles from './index.module.scss';
import { useParams } from 'react-router-dom';
Expand Down Expand Up @@ -37,7 +37,7 @@ const CustomizedProductsDisplay: FC<BodySearchProducts> = ({ subcategory }) => {

useEffect(() => {
searchProducts({
page: FIRST_PAGE,
page: Number(PageNumbers.FIRST_PAGE),
size: SIMILAR_PRODUCTS_SIZE,
body: {
subcategory,
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/create-pages-list.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PageNumbers } from 'utils/constants';

const createPagesList = (pagesAmount: PageNumbers) => {
const pagesArray: number[] = [];
for (let i = 1; i <= Number(pagesAmount); i++) {
pagesArray.push(i);
}
return pagesArray;
};

export { createPagesList };
Copy link
Collaborator

Choose a reason for hiding this comment

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

const numericValues = Object.values(PageNumbers)
.filter(value => typeof value === 'number');

1 change: 1 addition & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { getTotalPrice } from './get-total-price.helper';
export { isMatchingItem } from './is-matching-item.helper';
export { generateKey } from './generate-key.helper';
export { getSelectStyle } from './get-select-styles.helper';
export { createPagesList } from './create-pages-list.helper';
4 changes: 3 additions & 1 deletion src/hooks/use-get-viewport-width.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { useState, useEffect, useCallback } from 'react';
import { ViewportWidth } from 'utils/constants';

export const useGetViewportWidth = () => {
const [isMobile, setIsMobile] = useState(false);
const [isMobile, setIsMobile] = useState(
window.innerWidth <= ViewportWidth.MOBILE,
);

const handleResize = useCallback(() => {
const isMobileWidth = window.innerWidth <= ViewportWidth.MOBILE;
Expand Down
1 change: 0 additions & 1 deletion src/modules/core/components/CoreSwiper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const CoreSwiper: FC<CoreSwiperProps> = ({
effect="fade"
fadeEffect={{ crossFade: true }}
rewind
loop
Copy link
Collaborator

Choose a reason for hiding this comment

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

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In case of using "loop" the following error occurs while resizing the window:
image

It is mentioned here:
"Uncaught error when unmounting Swiper with loop on window resize #7265"
nolimits4web/swiper#7265

Also it seems the functionality has not been impacted by removing the "loop".

>
{children}
</Swiper>
Expand Down
3 changes: 3 additions & 0 deletions src/modules/core/components/Ellipsis/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ellipsis {
cursor: default;
}
12 changes: 12 additions & 0 deletions src/modules/core/components/Ellipsis/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { ELLIPSIS, PageNumbers } from 'utils/constants';

import styles from './index.module.scss';

const Ellipsis = (): React.JSX.Element => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

JSX.Element

<li key={ELLIPSIS} className={styles.ellipsis}>
{PageNumbers.ELLIPSIS}
</li>
);

export default Ellipsis;
5 changes: 4 additions & 1 deletion src/modules/core/components/MainLayout/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
align-items: center;
max-width: $max-content-width;
width: calc(100% - 160px);
height: 100%;
@include media(laptop) {
width: calc(100% - 120px);
}
Expand All @@ -17,3 +16,7 @@
width: calc(100% - 64px);
}
}

.mainMaxHeight {
height: 100%;
}
11 changes: 9 additions & 2 deletions src/modules/core/components/MainLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import styles from './index.module.scss';
interface MainLayoutProps {
children: ReactNode;
showFooter?: boolean;
isLoading?: boolean;
}

const MainLayout: FC<MainLayoutProps> = ({ children, showFooter = true }) => (
const MainLayout: FC<MainLayoutProps> = ({
children,
showFooter = true,
isLoading,
}) => (
<>
<Header />
<div className={styles.main}>{children}</div>
<div className={`${styles.main} ${isLoading ? styles.mainMaxHeight : ''}`}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<div className={`${styles.main} ${isLoading ? styles.mainMaxHeight : ''}`}>
<div className={getValidClassNames(styles.main, { [styles.mainMaxHeight]: isLoading })}>

{children}
</div>
{showFooter ? <Footer /> : null}
</>
);
Expand Down
14 changes: 14 additions & 0 deletions src/modules/core/components/PaginationButton/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import 'styles/constants';

.paginationButton:hover {
cursor: pointer;
}

.paginationDisabled {
pointer-events: none;
}

.pagination__icon {
width: 32px;
height: 32px;
}
44 changes: 44 additions & 0 deletions src/modules/core/components/PaginationButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { FC } from 'react';
import ArrowLeft from 'assets/svgs/ArrowLeft';
import ArrowRight from 'assets/svgs/ArrowRight';
import ArrowLeftGrey from 'assets/svgs/ArrowLeftGrey';
import ArrowRightGrey from 'assets/svgs/ArrowRightGrey';

import styles from './index.module.scss';

interface PaginationButtonProps {
isPrevious?: boolean;
isDisabled?: boolean;
handleClick: () => void;
}

const PaginationButton: FC<PaginationButtonProps> = ({
isPrevious,
isDisabled,
handleClick,
}) => {
return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

direct return

<button
className={`${styles.paginationButton} ${
isDisabled ? styles.paginationDisabled : ''
}`}
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider using getValidClassNames

onClick={handleClick}
>
<div className={styles.pagination__icon}>
{isDisabled ? (
isPrevious ? (
<ArrowLeftGrey />
) : (
<ArrowRightGrey />
)
) : isPrevious ? (
<ArrowLeft />
) : (
<ArrowRight />
)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider using a helper for readability

Copy link
Collaborator

Choose a reason for hiding this comment

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

at least create a separate constant in this component and don't use nested ternary operator

</div>
</button>
);
};

export default PaginationButton;
20 changes: 15 additions & 5 deletions src/modules/product/components/FilterTabButtons/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import React, { FC, useCallback, useState } from 'react';
import React, { FC, useCallback } from 'react';
import { BodySearchProducts } from 'redux/types';
import { getButtons } from './data';
import { useTranslation } from 'react-i18next';
import { Category, Subcategory } from 'types/types';
import { PageNumbers } from 'utils/constants';

import styles from './index.module.scss';

interface FilterTabButtons {
activeButton: string;
setActiveButton: (value: string) => void;
setActivePage: (page: PageNumbers) => void;
handleClick: (body: BodySearchProducts) => void;
}

const FilterTabButtons: FC<FilterTabButtons> = ({ handleClick }) => {
const FilterTabButtons: FC<FilterTabButtons> = ({
activeButton,
setActiveButton,
handleClick,
setActivePage,
}) => {
const { t } = useTranslation();

const buttons = getButtons(t);
const [active, setActive] = useState<string>(buttons[0].value);

const onClick = useCallback(
(value: string, body: BodySearchProducts) => () => {
handleClick(body);
setActive(value);
setActiveButton(value);
setActivePage(PageNumbers.FIRST_PAGE);
},
[],
);
Expand All @@ -38,7 +48,7 @@ const FilterTabButtons: FC<FilterTabButtons> = ({ handleClick }) => {
<button
key={value}
value={value}
className={value === active ? styles.active : styles.button}
className={value === activeButton ? styles.active : styles.button}
onClick={onClick(value, body)}
>
{name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
width: calc((100% - 16px) / 3);
@include media(mobile) {
width: calc((100% - 8px) / 2);
margin-bottom: 8px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
width: 100%;
height: 100%;
margin-bottom: 16px;
@include media(mobile) {
margin-bottom: 12px;
}
}

.wrapperArrows {
Expand Down
5 changes: 1 addition & 4 deletions src/modules/product/components/ProductInfo/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
margin-bottom: 10px;
}

.productName {
Expand All @@ -18,9 +18,6 @@
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
@include media(tablet) {
margin-bottom: 5px;
}
}

.shoppingCart {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/product/components/ProductsGrid/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 68px;
width: 100%;
row-gap: 32px;
margin-bottom: 64px;
@include media(mobile) {
margin-bottom: 32px;
row-gap: 16px;
margin-bottom: 32px;
}
}
Loading
Loading