Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbacz committed Apr 8, 2022
1 parent e9cd81c commit c101c0f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
14 changes: 7 additions & 7 deletions web/src/components/pages/productsPage/ProductsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React, { useState } from 'react';
import { ReadonlyProductArray } from '../../../interfaces/product';
import { Product } from '../../../interfaces/product';
import { ProductItem } from '../../shared/productItem/ProductItem';
import { SearchInput } from '../../shared/searchInput/SearchInput';
import './style.css';

type ProductsPageType = {
header: string;
};
const products: ReadonlyProductArray[] = [
const products: Product[] = [
{
id: 'test',
name: 'Adidas 2000',
description: 'Some description',
price: 100,
size: 'x1',
img: 'https://w.eobuwie.com.pl/media/citalog/product/cache/image/650x650/0/e/0900300028753_01_st.jpg',
img: 'https://www.eobuwie.com.pl/media/catalog/product/cache/image/650x650/0/0/0000201282847_01_fp.jpg',
productType: '',
productCategory: '',
brand: '',
Expand All @@ -25,20 +25,20 @@ const products: ReadonlyProductArray[] = [
description: 'Some description 5e00',
price: 125,
size: 'l',
img: 'https://w.eobuwie.com.pl/media/citalog/product/cache/image/650x650/0/e/0900300028753_01_st.jpg',
img: 'https://www.eobuwie.com.pl/media/catalog/product/cache/image/650x650/0/0/0000206708137_1__1.jpg',
productType: '',
productCategory: '',
brand: '',
},
];

export const ProductsPage = ({ header }: ProductsPageType): JSX.Element => {
const [filteredProducts, setFilteredProducts] = useState<ReadonlyProductArray[]>(products);
const [filteredProducts, setFilteredProducts] = useState<Product[]>(products);

const searchProduct = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
debugger;
const results: ReadonlyProductArray[] = products.filter(
const results: Product[] = products.filter(
(product) =>
product.name.toLowerCase().includes(value.toLowerCase()) ||
product.description.toLowerCase().includes(value.toLowerCase())
Expand All @@ -50,7 +50,7 @@ export const ProductsPage = ({ header }: ProductsPageType): JSX.Element => {
return (
<div className="products__page">
<h2 className="products__page__title">{header}</h2>
<SearchInput onSearch={searchProduct} />
{/* <SearchInput onSearch={searchProduct} /> */}
<div className="products__page__items">
{filteredProducts.map((item) => {
return <ProductItem key={item.id} {...item} />;
Expand Down
5 changes: 2 additions & 3 deletions web/src/components/shared/productItem/ProductItem.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';
import { ReadonlyProductArray } from '../../../interfaces/product';
import { Product } from '../../../interfaces/product';
import './style.css';

export const ProductItem = ({ img, name, description, price, id }: ReadonlyProductArray): JSX.Element => {
export const ProductItem = ({ img, name, description, price, id }: Product): JSX.Element => {
return (
<div className="item">
<div className="item__header">
<img className="item__header__image" src={img} alt={name}></img>

</div>
<div className="item__body">
<div className="item__body__title">
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/shared/productItem/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.item{
width: 350px;
height:500x;
height:500px;
margin-bottom: 50px;
margin-top: 50px;
margin-left: 50px;
Expand Down
10 changes: 5 additions & 5 deletions web/src/contexts/cartProvider/CartProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { createContext, useState } from 'react';
import { ProductItemType } from '../../components';
import { Product } from '../../interfaces/product';

export interface cartContextData {
cart: ProductItemType[];
addItem: (value: ProductItemType) => void;
cart: Product[];
addItem: (value: Product) => void;
}

const contextDefaultValues: cartContextData = {
Expand All @@ -18,9 +18,9 @@ interface providerProps {
export const CartContext = createContext<cartContextData>(contextDefaultValues);

export const CartProvider = ({ children }: providerProps) => {
const [cart, setCart] = useState<ProductItemType[]>(contextDefaultValues.cart);
const [cart, setCart] = useState<Product[]>(contextDefaultValues.cart);

const addItem = (newItem: ProductItemType) => {
const addItem = (newItem: Product) => {
setCart((cart) => [...cart, newItem]);
};

Expand Down
12 changes: 5 additions & 7 deletions web/src/contexts/pageResourceProvider/PageResourceProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { createContext, useState } from 'react';
import { ProductItemType } from '../../components';
import { Product } from '../../interfaces/product';

export interface pageResourceContextData {
pageResource: ProductItemType[];
addPageResource: (value: ProductItemType[]) => void;
pageResource: Product[];
addPageResource: (value: Product[]) => void;
}

const contextDefaultValues: pageResourceContextData = {
Expand All @@ -18,11 +18,9 @@ interface providerProps {
export const PageResourceContext = createContext<pageResourceContextData>(contextDefaultValues);

export const PageResourceProvider = ({ children }: providerProps) => {
const [pageResource, setPageResource] = useState<ProductItemType[]>(
contextDefaultValues.pageResource
);
const [pageResource, setPageResource] = useState<Product[]>(contextDefaultValues.pageResource);

const addPageResource = (data: ProductItemType[]) => {
const addPageResource = (data: Product[]) => {
setPageResource(data);
};

Expand Down
2 changes: 1 addition & 1 deletion web/src/interfaces/product.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ReadonlyProductArray = {
export type Product = {
id: string;
name: string;
description: string;
Expand Down

0 comments on commit c101c0f

Please sign in to comment.