Skip to content

Commit

Permalink
added updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ihorivna007 committed Aug 23, 2023
1 parent f024716 commit bfc4a9b
Show file tree
Hide file tree
Showing 26 changed files with 385 additions and 237 deletions.
4 changes: 4 additions & 0 deletions src/Routes/Route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import { CardPage } from '../pages/CardPage';
import { FavoritePage } from '../pages/FavoritePage';
import { CartPage } from '../pages/CartPage';
import { NotFoundPage } from '../pages/NotFoundPage';
import { TabletsPage } from '../pages/TabletsPage';
import { AccessoriesPage } from '../pages/AccessoriesPage';

export const AppRoutes = () => {
return (
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/phones" element={<PhonesPage />} />
<Route path="/phones/:id" element={<CardPage />} />
<Route path="/tablets" element={<TabletsPage />} />
<Route path="/accessories" element={<AccessoriesPage />} />
<Route path="/favorites" element={<FavoritePage />} />
<Route path="/cart" element={<CartPage />} />
<Route path="*" element={<NotFoundPage />} />
Expand Down
4 changes: 4 additions & 0 deletions src/api/getData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const getProducts = async () => {
return client.get<Product[]>('/products.json');
};

export const getTablets = async () => {
return client.get<Product[]>('/products.json');
};

export const getDescription = async (id: string) => {
return client.get<ProductInfo>(`/products/${id}.json`);
};
8 changes: 8 additions & 0 deletions src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export const Banner = () => {
});
};

useEffect(() => {
const interval = setInterval(() => {
handleBannerScroll(1);
}, 5000);

return () => clearInterval(interval);
}, []);

useEffect(() => {
const dots = document.querySelector('.banner__dots');

Expand Down
2 changes: 1 addition & 1 deletion src/components/Catalog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Product } from '../types/Product';
import { Card } from './Card';
import { Card } from './ProductCard';

type Props = {
catalog: Product[],
Expand Down
8 changes: 4 additions & 4 deletions src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { SearchLink } from './SearchLink';
const sortByCategories = [
'Default',
'Newest',
'Lowest Price',
'Highest Price',
'Alphabetically',
'Cheapest',
];

const itemsOnPage = [8, 12, 16, 24];
const itemsOnPage = [4, 8, 16, 'All'];

type Props = {
type: string,
Expand All @@ -24,7 +24,7 @@ export const Dropdown:React.FC<Props> = ({
const [searchParams] = useSearchParams();
const params = isSortBy
? searchParams.get(type) || 'Default'
: parseInt(searchParams.get(type) || '12', 10);
: searchParams.get(type) || '8';

const title = isSortBy ? 'Sort By' : 'Items on page';
const category = isSortBy ? sortByCategories : itemsOnPage;
Expand Down
22 changes: 15 additions & 7 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Link, NavLink } from 'react-router-dom';
import classNames from 'classnames';
import { NavLink } from 'react-router-dom';

const linkClassNames = (
{ isActive } : { isActive : boolean },
) => classNames('footer__link text__uppercase', { active: isActive });

export const Footer = () => {
const scrollToTop = () => {
Expand All @@ -12,15 +17,18 @@ export const Footer = () => {
</div>

<div className="footer__centre">
<Link className="text__uppercase" to="/github">
<NavLink
className={linkClassNames}
to="https://github.com/ihorivna007/react_phone-catalog/tree/develop"
>
github
</Link>
<Link className="text__uppercase" to="/contacts">
</NavLink>
<NavLink className={linkClassNames} to="/contacts">
contacts
</Link>
<Link className="text__uppercase" to="/rights">
</NavLink>
<NavLink className={linkClassNames} to="/rights">
rights
</Link>
</NavLink>
</div>

<div className="footer__right">
Expand Down
3 changes: 2 additions & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const iconClassNames = (
) => classNames('header__icon', { active: isActive });

const headerLinks = ['home', 'phones', 'tablets', 'accessories'];
const pageWithSearchBar = ['/phones', '/tablets', '/accessories', '/favorites'];

export const Header:React.FC = () => {
const { pathname } = useLocation();
const searchBarIsPresent
= pathname === '/phones' || pathname === '/favorites';
= pageWithSearchBar.includes(pathname);
const cartIsActive = pathname === '/cart';

const menuIsPresent = pathname === '/';
Expand Down
4 changes: 3 additions & 1 deletion src/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type Props = {
};
const headerLinks = ['home', 'phones', 'tablets', 'accessories'];
const footerLinks = ['github', 'contacts', 'rights'];
const githubLink
= 'https://github.com/ihorivna007/react_phone-catalog/tree/develop';

export const Menu:React.FC<Props> = ({ isMenuOpened }) => (
<div className="menu">
Expand All @@ -30,7 +32,7 @@ export const Menu:React.FC<Props> = ({ isMenuOpened }) => (
<NavLink
key={link}
className="text__uppercase"
to={`/${link}`}
to={link === 'github' ? githubLink : `/${link}`}
>
{link}
</NavLink>
Expand Down
13 changes: 13 additions & 0 deletions src/components/NoResults.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type Props = {
category: string,
};

export const NoResults:React.FC<Props> = ({ category }) => {
const title = category.slice(0, 1).toUpperCase() + category.slice(1);

return (
<div className="page__not-found">
<h3>{`${title} not found`}</h3>
</div>
);
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useState } from 'react';
import FadeLoader from 'react-spinners/FadeLoader';
import { Product } from '../types/Product';
import { Card } from './Card';
import { Card } from './ProductCard';

type Props = {
title: string,
itemsList: Product[],
isLoading: boolean,
};

export const ItemsSlider:React.FC<Props> = ({
export const ProductsSlider: React.FC<Props> = ({
title,
itemsList,
isLoading,
Expand Down
9 changes: 5 additions & 4 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const SearchBar: React.FC<Props> = ({ category }) => {
{ query: event.target.value || null }));
};

const mobileVersion = window.innerWidth <= 768;
const placeholder = mobileVersion ? 'on page' : `in ${category}`;

const clearQuery = () => {
setSearchParams(getSearchWith(searchParams, { query: '' }));
};
Expand All @@ -24,7 +27,7 @@ export const SearchBar: React.FC<Props> = ({ category }) => {
<input
className="header__search__input"
type="text"
placeholder={`Search in ${category}...`}
placeholder={`Search ${placeholder}...`}
onChange={handleSearchBar}
value={query}
/>
Expand All @@ -35,9 +38,7 @@ export const SearchBar: React.FC<Props> = ({ category }) => {
className="icon icon--close close-button"
onClick={clearQuery}
/>
) : (
window.innerWidth > 768 && <p className="icon icon--search" />
)}
) : <p className="icon icon--search" />}
</div>
);
};
6 changes: 5 additions & 1 deletion src/helpers/cartTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ export const cartListAdded = (cartId: string) => {
};

export const checkIsSelected = (id: string) => {
return !!findItem(selectedList, id);
if (selectedList.length > 0) {
return !!findItem(selectedList, id);
}

return false;
};
5 changes: 5 additions & 0 deletions src/pages/AccessoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ProductsPage } from './ProductsPage';

export const AccessoriesPage: React.FC = () => (
<ProductsPage title="Accessories" category="accessories" />
);
4 changes: 2 additions & 2 deletions src/pages/CardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Product } from '../types/Product';
import { ProductInfo } from '../types/ProductInfo';
import { customColors } from '../helpers/customColors';

import { ItemsSlider } from '../components/ItemsSlider';
import { ProductsSlider } from '../components/ProductsSlider';
import { Navigation } from '../components/Navigation';
import { HistoryBackButton } from '../components/HistoryBackButton';
import { FavoriteButton } from '../components/FavoriteButton';
Expand Down Expand Up @@ -273,7 +273,7 @@ export const CardPage: React.FC = () => {
</div>
</div>
</section>
<ItemsSlider
<ProductsSlider
title="You may also like"
itemsList={properties.filter(item => item.id !== currentProduct.id)}
isLoading={false}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useState } from 'react';
import { getProducts } from '../api/getData';
import { Product } from '../types/Product';
import { ItemsSlider } from '../components/ItemsSlider';
import { ProductsSlider } from '../components/ProductsSlider';
import { Banner } from '../components/Banner';
import { Category } from '../components/Category';

Expand Down Expand Up @@ -45,15 +45,15 @@ export const HomePage: React.FC = () => {
<main className="page">
<Banner />

<ItemsSlider
<ProductsSlider
title="Hot price"
itemsList={hotPriceList}
isLoading={isLoading}
/>

<Category />

<ItemsSlider
<ProductsSlider
title="Brand new models"
itemsList={newModelsList}
isLoading={isLoading}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NotFoundPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const NotFoundPage = () => (
<div>
<Navigation />
<div className="page">
<h2>Not Found Page</h2>
<h1>Page not found</h1>
</div>
</div>
);
Loading

0 comments on commit bfc4a9b

Please sign in to comment.