Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
LBondarchuk committed Jul 14, 2023
1 parent 3939ac1 commit 9000f0a
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 40 deletions.
52 changes: 39 additions & 13 deletions src/components/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const Pagination:React.FC<Props> = ({ paginationLength }) => {
const firstVisiblePage = useRef(0);
const [shift, setShift] = useState(0);

const showLastItem = lastVisiblePage.current !== paginationLength
&& paginationLength > paginationLimit;

useEffect(() => {
if (paginationLimit) {
if (+page > paginationLimit && +page > lastVisiblePage.current) {
Expand Down Expand Up @@ -56,13 +59,10 @@ export const Pagination:React.FC<Props> = ({ paginationLength }) => {
};

const createPagination = () => {
if (!paginationLength) {
return (<li className="pagination__item is-active">1</li>);
}

const result = [];

for (let i = 0; i < paginationLength; i += 1) {
for (let i = 0; i < (showLastItem
? paginationLength - 1 : paginationLength); i += 1) {
result.push(
<li
key={i + 1}
Expand All @@ -74,7 +74,6 @@ export const Pagination:React.FC<Props> = ({ paginationLength }) => {
style={{ left: -shift }}
>
{i + 1}

</li>,
);
}
Expand All @@ -85,20 +84,47 @@ export const Pagination:React.FC<Props> = ({ paginationLength }) => {
const paginationList = createPagination();

return (
<section className="pagination">
<section
className="pagination"
style={{ left: showLastItem ? -step / 2 : 0 }}
>
<ArrowButton
type="left"
stop={+page === 1}
onChangePosition={() => handleChangePage(+page - 1)}
/>
<ul className="pagination__list">
<ul
className="pagination__list"
>
{paginationList}
</ul>
<ArrowButton
type="right"
stop={+page === paginationLength}
onChangePosition={() => handleChangePage(+page + 1)}
/>
<div
className="right-button"
style={{ left: showLastItem ? step : 0 }}
>
{showLastItem && paginationLimit !== 0
&& (
<button
type="button"
className="pagination__item"
style={{
position: 'absolute',
left: -step,
}}
onClick={() => handleChangePage(paginationLength)}
>
{+page !== paginationLength - 1 && '...'}
{paginationLength}
</button>
)}
<ArrowButton
type="right"
stop={+page === paginationLength}
onChangePosition={() => handleChangePage(+page + 1)}
/>
</div>

</section>

);
};
25 changes: 22 additions & 3 deletions src/components/pages/CartPage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useMemo, useContext } from 'react';
import {
useMemo, useContext, useState, useEffect,
} from 'react';
import { TransitionGroup, CSSTransition } from 'react-transition-group';
import { Cart } from '../../utils/types/Cart';
import { Context } from '../../utils/Context';
import { BlockTitle } from '../BlockTitle';

export const CartPage: React.FC = () => {
const { cartList, editCartItem } = useContext(Context);
const [shift, setShift] = useState(-700);

const handleRemoveItem = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
Expand All @@ -20,6 +23,12 @@ export const CartPage: React.FC = () => {
.reduce((acum, item) => acum + item.price * item.quantity, 0);
}, [cartList]);

useEffect(() => {
const timerId = setTimeout(() => setShift(-700), 5000);

return () => clearTimeout(timerId);
}, [shift]);

return (
<main className="cart">
<BlockTitle title="Cart" subtitle={cartList.length} />
Expand All @@ -28,7 +37,17 @@ export const CartPage: React.FC = () => {
<h1>{`$${totalAmount}`}</h1>
<p>{`Total for ${cartList.length} items`}</p>
</div>
{cartList.length > 0 && (<button type="submit">Checkout</button>)}
{cartList.length > 0 && (
<button
type="button"
onClick={() => setShift(18)}
>
Checkout
</button>
)}
</div>
<div className="cart__total--message" style={{ right: shift }}>
<span>The option will be available soon</span>
</div>
<ul className="cart__list">
<TransitionGroup className="cart__list">
Expand All @@ -40,7 +59,7 @@ export const CartPage: React.FC = () => {
>
<li className="cart__item" key={item.id}>
<button
type="submit"
type="button"
onClick={(e) => handleRemoveItem(e, item)}
className="cart__item--remove"
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/ProductsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const ProductsPage:React.FC<Props> = ({ products }) => {
subtitle={0}
title={developedPages[0] === Path
? 'No matches found'
: 'Page under development...'}
: 'Product category will be added soon...'}
/>
)}

Expand Down
6 changes: 6 additions & 0 deletions src/scss/categories/categories.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
@import "../utils/mixins";
@import "../utils/variables";

@import "./categories-item.scss";

.categories {
margin-bottom: 80px;

&__title {
@include text (32px, 700, $primary-dark-color);
}

&__items {
display: flex;
gap: 16px;
Expand Down
12 changes: 4 additions & 8 deletions src/scss/icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
}

& img {
width: 25px;

@include onPhone {
width: 18px;
}
width: 15px;
}

&-info__info {
Expand All @@ -28,9 +24,9 @@
bottom: 53%;
font-size: 70%;
color: #e2e6e9;
width: 15px;
height: 15px;
background: #eb0909;
width: 13px;
height: 13px;
background: #eb5757;
border: 1px solid #fff;
border-radius: 50%;
}
Expand Down
2 changes: 1 addition & 1 deletion src/scss/page-navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

& span {
color: $primary-gray-color;
@include text (12px, 600, $primary-gray-color);
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/scss/pages/cart-page/cart-total.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,22 @@
background: $primary-dark-color;
color: #fff;
}

&--message {
position: absolute;
@extend .flex-center;
transition: right 0.8s ease;
width: 500px;
height: 100px;
border: 1px solid $border-color-gray;

@include onPhone {
width: 300px;
}

& span {
@include text (14px, 600, $primary-gray-color);
}
}
}
}
10 changes: 1 addition & 9 deletions src/scss/pagination/pagination-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
&__list {
display: flex;
gap: 8px;
@include onTab {
max-width: 85%;
overflow: hidden;
}

@include onPhone {
width: 85%;
overflow: hidden;
}
overflow: hidden;
}
}
11 changes: 9 additions & 2 deletions src/scss/pagination/pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
@import "./pagination-item.scss";

.pagination {
position: relative;
@extend .flex-center;
gap: 16px;
margin: 0 auto 80px;

@include onTab {
gap: 20px;
}

@include onPhone {
gap: 8px;
}
gap: 16px;
margin: 0 auto 80px;
}

.right-button {
position: relative;
}
2 changes: 2 additions & 0 deletions src/scss/product-slider..scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "./utils/mixins";
@import "./utils/variables";

.product-slider {
overflow: hidden;
Expand All @@ -11,6 +12,7 @@
}

&__title {
@include text (32px, 700, $primary-dark-color);
margin: 0;
}

Expand Down
8 changes: 7 additions & 1 deletion src/scss/search.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "./utils/_variables";
@import "./utils/extends";
@import "./utils/mixins";

.search {
@extend .flex-between-center;
Expand All @@ -17,9 +18,14 @@
input {
outline: none;
border: none;
width: 327px;

&::placeholder {
color: $border-color-gray;
@include text (14px, 600, $primary-gray-color);
}

@include onTab {
width: 130px;
}

@include onPhone {
Expand Down
3 changes: 2 additions & 1 deletion src/scss/select-block/item.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@import "../utils/variables";
@import "../utils/mixins";

.filter {
&__item {
color: $primary-gray-color;
@include text(14px, 600, $primary-gray-color );
padding: 10px 16px;
cursor: pointer;
transition: box-shadow 0.2s ease;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/useDeviceSize/deviceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const paginationLimit = {
tab: Math.ceil(
(main.tab.size - ((buttonWidth + main.tab.gap) * 2)) / (buttonWidth + 8),
),
desktop: 0,
desktop: 30,
};

export const itemsOnPage = {
Expand Down

0 comments on commit 9000f0a

Please sign in to comment.