Skip to content

Commit

Permalink
developpp
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-medushevskyi committed Jul 27, 2023
1 parent cec9cd5 commit 1d83974
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Route, Routes, useLocation } from 'react-router-dom';
import './App.scss';
import { useEffect } from 'react';
import { FavoriteContextProvider } from './FavoriteContext';
import { FavoriteContextProvider } from './core/context/FavoriteContext/FavoriteContext';

Check failure on line 4 in src/App.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 89. Maximum allowed is 80
import { HomePage } from './Components/Pages/HomePage';
import { Header } from './Components/Header';
import { NotFoundPage } from './Components/Pages/NotFoundPage';
Expand Down
2 changes: 0 additions & 2 deletions src/Components/Footer/Footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ html {
background-repeat: no-repeat;
transition: 0.3s;
&:hover {
height: 32px;
width: 48px;
cursor: pointer;
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/Components/Header/Header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,12 @@
transition: .3s;

&:hover {
height: 32px;
width: 48px;
cursor: pointer;
}
}

.color-toggle {
background-color: blue;
/* Цвет по умолчанию */
color: white;
padding: 10px;
border: none;
Expand All @@ -218,7 +215,6 @@

.color-toggle.gray {
background-color: gray;
/* Цвет при выбранном состоянии */
}

.search-input {
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { HeaderSearch } from './HeaderSearch';
import HeartImage from './HeaderImage/heart.svg';
import BasketImage from './HeaderImage/basket.svg';
import LogoImage from './HeaderImage/LOGO.svg';
import { useFavoriteContext } from '../../FavoriteContext';
import { useFavoriteContext }
from '../../core/context/FavoriteContext/FavoriteContext';

interface HeaderProps {
searchValue: string;
Expand All @@ -21,7 +22,6 @@ export const Header = ({ searchValue, setSearchValue }: HeaderProps) => {
const accessories = location.pathname === '/accessories';
const basket = location.pathname === '/cart';
const favorite = location.pathname === '/favorites';
// const [showSearch, setShowSearch] = useState(!isHomePage);

let search = '';

Expand Down
6 changes: 6 additions & 0 deletions src/Components/Header/HeaderImage/LOGOGray.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Components/Pages/Basket/Basket.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useFavoriteContext } from '../../../FavoriteContext';
import { useFavoriteContext } from '../../../core/context/FavoriteContext/FavoriteContext';

Check failure on line 3 in src/Components/Pages/Basket/Basket.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 91. Maximum allowed is 80
import products from '../../../new/products.json';
import { NotFoundPage } from '../NotFoundPage/NotFoundPage';
import './Basket.scss';
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Pages/Basket/BlockBasket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Product } from '../../ProductCards/Product';
import Plus from './BasketImage/Plus.svg';
import Minus from './BasketImage/Minus.svg';
import CLose from './BasketImage/Close.svg';
import { useBasketContext } from '../../../FavoriteContext';
import { useBasketContext } from '../../../core/context/FavoriteContext/FavoriteContext';

Check failure on line 8 in src/Components/Pages/Basket/BlockBasket.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 89. Maximum allowed is 80

interface ProductCardsProps {
product: Product,
Expand Down
6 changes: 0 additions & 6 deletions src/Components/Pages/Contacts/Contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import github from './ContactsImage/github.svg';
import gmail from './ContactsImage/gmail.svg';
import Linkdn from './ContactsImage/Linkdn.svg';
import phone from './ContactsImage/phone.svg';
import slack from './ContactsImage/slack.svg';
import telegram from './ContactsImage/telegram.svg';
import instagram from './ContactsImage/instagram.svg';

Expand Down Expand Up @@ -39,11 +38,6 @@ const contactData = [
text: '+380 999 580 209',
linkImage: 'tel:+380999580209',
},
{
image: slack,
text: 'Nazar Medushevskyi',
linkImage: 'https://github.com/nazar-medushevskyi',
},
{
image: telegram,
text: 'MedushevskiyN',
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Pages/Favorite/BlockFavorite.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProductCards } from '../../ProductCards/ProductCards';
import './Favorite.scss';
import products from '../../../new/products.json';
import { useFavoriteContext } from '../../../FavoriteContext';
import { useFavoriteContext } from '../../../core/context/FavoriteContext/FavoriteContext';

Check failure on line 4 in src/Components/Pages/Favorite/BlockFavorite.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 91. Maximum allowed is 80

export const BlockFavorite = () => {
const { favorites } = useFavoriteContext();
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Pages/Favorite/Favorite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link } from 'react-router-dom';
import { BlockFavorite } from './BlockFavorite';
import HomeImage from './FavoriteImage/Home.svg';
import Arrowimage from './FavoriteImage/Arrow.svg';
import { useFavoriteContext } from '../../../FavoriteContext';
import { useFavoriteContext } from '../../../core/context/FavoriteContext/FavoriteContext';

Check failure on line 6 in src/Components/Pages/Favorite/Favorite.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 91. Maximum allowed is 80
import { NotFoundPage } from '../NotFoundPage/NotFoundPage';

export const Favorite = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useBasketContext } from '../../../FavoriteContext';
import { useBasketContext } from '../../../core/context/FavoriteContext/FavoriteContext';

Check failure on line 1 in src/Components/PhonesPageInfo/PhonesPageInfoButton/PhonesPageInfoButton.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 89. Maximum allowed is 80
import './PhonesPageInfoButton.scss';

interface Info {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useFavoriteContext } from '../../../FavoriteContext';
import { useFavoriteContext } from '../../../core/context/FavoriteContext/FavoriteContext';

Check failure on line 1 in src/Components/PhonesPageInfo/PhonesPageInfoFovorite/PhonesPageInfoFovorite.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 91. Maximum allowed is 80
import heartImage from './PhonesPageInfoFavoriteImages/heart.svg';
import './PhonesPageInfoFovorite.scss';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useFavoriteContext } from '../../../FavoriteContext';
import { useFavoriteContext } from '../../../core/context/FavoriteContext/FavoriteContext';

Check failure on line 1 in src/Components/ProductCards/ProductsCardsButton/ProductsCardsButton.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 91. Maximum allowed is 80
import { Product } from '../Product';
import './ProductsCardsButton.scss';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import heartImage from './ProductsCardsFavoriteImage/heart.svg';
import './ProductsCardsFavorite.scss';
import { Product } from '../Product';
import { useFavoriteContext } from '../../../FavoriteContext'; // Укажите правильный путь к FavoriteContext
import { useFavoriteContext } from '../../../core/context/FavoriteContext/FavoriteContext'; // Укажите правильный путь к FavoriteContext

Check failure on line 4 in src/Components/ProductCards/ProductsCardsFavorite/ProductsCardsFavorite.tsx

View workflow job for this annotation

GitHub Actions / run_linter (14.x)

This line has a length of 91. Maximum allowed is 80

interface ProductFavoriteProps {
product: Product;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@ import React, {
createContext, useContext, useEffect, useState,
} from 'react';

interface FavoriteContextValue {
basket: { id: string; price: number; quantity: number }[];
favorites: string[];
addToFavorites: (productId: string) => void;
removeFromFavorites: (productId: string) => void;
addToBasket: (productId: string) => void;
removeFromBasket: (productId: string) => void;
removeFromAllB: (productId: string) => void;
favoritesLength: number;
basketLength: number;
}

const FavoriteContext = createContext<FavoriteContextValue
| undefined>(undefined);
import { FavoriteContextValue } from './types';

const noop = () => {
//
};

const FavoriteContext = createContext<FavoriteContextValue>({
basket: [],
favorites: [],
addToBasket: noop,
addToFavorites: noop,
removeFromFavorites: noop,
removeFromBasket: noop,
removeFromAllB: noop,
favoritesLength: 0,
basketLength: 0,
});

export const useFavoriteContext = () => {
const context = useContext(FavoriteContext);

if (!context) {
throw new Error(`useFavoriteContext must be used within
a FavoriteContextProvider`);
throw new Error(
'useFavoriteContext must be used within a FavoriteContextProvider',
);
}

return context;
Expand All @@ -32,8 +36,9 @@ export const useBasketContext = () => {
const context = useContext(FavoriteContext);

if (!context) {
throw new Error(`useBasketContext must be used
within a FavoriteContextProvider`);
throw new Error(
'useBasketContext must be used within a FavoriteContextProvider',
);
}

return context;
Expand All @@ -42,7 +47,7 @@ export const useBasketContext = () => {
export const FavoriteContextProvider: React.FC = ({ children }) => {
const [favorites, setFavorites] = useState<string[]>([]);
const [basket, setBasket] = useState<
{ id: string; price: number; quantity: number }[]>([]);
FavoriteContextValue['basket']>([]);

const addToFavorites = (productId: string) => {
setFavorites((prevFavorites) => [...prevFavorites, productId]);
Expand Down
1 change: 1 addition & 0 deletions src/core/context/FavoriteContext/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './FavoriteContext';
11 changes: 11 additions & 0 deletions src/core/context/FavoriteContext/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface FavoriteContextValue {
basket: { id: string; price: number; quantity: number }[];
favorites: string[];
addToFavorites: (productId: string) => void;
removeFromFavorites: (productId: string) => void;
addToBasket: (productId: string) => void;
removeFromBasket: (productId: string) => void;
removeFromAllB: (productId: string) => void;
favoritesLength: number;
basketLength: number;
}

0 comments on commit 1d83974

Please sign in to comment.