-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e31354b
commit 046178a
Showing
13 changed files
with
279 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
import { FC, useState, useEffect } from 'react'; | ||
|
||
import './App.scss'; | ||
|
||
import { Header } from './pages/components/Header'; | ||
import { HomePage } from './pages/HomePage'; | ||
import { PhonesPage } from './pages/PhonesPage'; | ||
import { Footer } from './pages/components/Footer'; | ||
import { getPhones } from './api/phone'; | ||
import { Phone } from './types/Phone'; | ||
// import { ProductDetailsPage } from './pages/ProductDetailsPage'; | ||
|
||
const App = () => ( | ||
<div className="App"> | ||
<Header /> | ||
<HomePage /> | ||
<PhonesPage /> | ||
{/* <ProductDetailsPage /> */} | ||
<Footer /> | ||
</div> | ||
); | ||
const App: FC = () => { | ||
const [phones, setPhones] = useState<Phone[]>([]); | ||
|
||
async function loadedPhones() { | ||
try { | ||
const result = await getPhones(); | ||
|
||
setPhones(result); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.log(error); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
loadedPhones(); | ||
}, []); | ||
|
||
return ( | ||
<div className="App"> | ||
<Header /> | ||
<HomePage phones={phones} /> | ||
<PhonesPage phones={phones} /> | ||
{/* <ProductDetailsPage /> */} | ||
<Footer /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable jsx-a11y/click-events-have-key-events */ | ||
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
import { | ||
Dispatch, FC, SetStateAction, useState, | ||
} from 'react'; | ||
import classNames from 'classnames'; | ||
// eslint-disable-next-line import/no-cycle | ||
import { SortByOptions } from '../PhonesPage'; | ||
import '../../styles/styles.scss'; | ||
|
||
type Props = { | ||
options: string[], | ||
defaultOption: string, | ||
onChange: Dispatch<SetStateAction<{ sortBy: string; itemsShow: string; }>>; | ||
}; | ||
|
||
const CustomSelect: FC<Props> = ({ options, defaultOption, onChange }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [selectedOption, setSelectedOption] = useState(defaultOption); | ||
|
||
const toggleDropdown = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const handleOptionClick = (option: string) => { | ||
setSelectedOption(option); | ||
setIsOpen(false); | ||
if (onChange) { | ||
if (SortByOptions.AGE === option | ||
|| SortByOptions.NAME === option | ||
|| SortByOptions.PRICE === option) { | ||
onChange((prev) => ({ ...prev, sortBy: option })); | ||
} else { | ||
onChange((prev) => ({ ...prev, itemsShow: option })); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="custom-select" onClick={toggleDropdown}> | ||
<div className="selected-option">{selectedOption}</div> | ||
{isOpen && ( | ||
<ul className={classNames( | ||
'options', | ||
{ 'options--opened': isOpen }, | ||
)} | ||
> | ||
{options.map((option: string) => ( | ||
<li | ||
// className= | ||
key={option} | ||
onClick={() => handleOptionClick(option)} | ||
> | ||
{option} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CustomSelect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
import { FC } from 'react'; | ||
// import { ProductCard } from './ProductCard'; | ||
import '../../styles/styles.scss'; | ||
import { Phone } from '../../types/Phone'; | ||
import { ProductCard } from './ProductCard'; | ||
|
||
export const ProductsList: FC = () => { | ||
type Props = { | ||
products: Phone[], | ||
}; | ||
|
||
export const ProductsList: FC<Props> = ({ products }) => { | ||
return ( | ||
<ul className="products-list"> | ||
<li className="products-list__item"> | ||
{/* <ProductCard /> */} | ||
</li> | ||
<li className="products-list__item"> | ||
{/* <ProductCard /> */} | ||
</li> | ||
<li className="products-list__item"> | ||
{/* <ProductCard /> */} | ||
</li> | ||
<li className="products-list__item"> | ||
{/* <ProductCard /> */} | ||
</li> | ||
<li className="products-list__item"> | ||
{/* <ProductCard /> */} | ||
</li> | ||
{products.map(product => ( | ||
<li className="products-list__item" key={product.id}> | ||
<ProductCard product={product} /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; |
Oops, something went wrong.