-
Notifications
You must be signed in to change notification settings - Fork 0
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
940229c
commit fb15098
Showing
30 changed files
with
1,782 additions
and
173 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { getInfo } from './api'; | ||
import './App.scss'; | ||
import { GoodsList } from './Components/GoodsList/GoodsList'; | ||
|
||
export function App() { | ||
const [data, setData] = useState([]); | ||
|
||
useEffect(() => { | ||
getInfo() | ||
.then(result => setData( | ||
result.map((item, index) => ({ | ||
...item, | ||
id: index + 1, | ||
}) | ||
) | ||
)); | ||
|
||
}, []) | ||
|
||
return ( | ||
<div className="App"> | ||
<GoodsList data={data} /> | ||
</div> | ||
); | ||
} |
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,13 @@ | ||
.App { | ||
text-align: center; | ||
position: relative; | ||
padding: 100px 20px; | ||
max-width: 1600px; | ||
margin: 0 auto; | ||
} | ||
|
||
@media screen and (max-width: 400px) { | ||
.App { | ||
padding: 50px 20px; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
import React from 'react'; | ||
import '../CurrentGood/currentGood.scss'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const CurrentGood = ({good, setIsOpen, setData}) => { | ||
|
||
return ( | ||
<div className="good"> | ||
<p className="good__category">{good.category}</p> | ||
<h3 className="good__name">{good.name}</h3> | ||
|
||
<div className="good__container"> | ||
<p className="good__price"> | ||
<span className="good__icon">$</span> | ||
{good.price} | ||
</p> | ||
<button | ||
type="button" | ||
className="good__button" | ||
onClick={() => { | ||
setIsOpen(true) | ||
setData(good) | ||
}} | ||
> | ||
buy | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
CurrentGood.propTypes = { | ||
good: PropTypes.shape({ | ||
category: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
price: PropTypes.number.isRequired, | ||
}).isRequired, | ||
setIsOpen: PropTypes.func.isRequired, | ||
setData: PropTypes.func.isRequired, | ||
} |
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,86 @@ | ||
@import '../../utils/mixins.scss'; | ||
@import '../../utils/vars.scss'; | ||
|
||
.good { | ||
width: 352px; | ||
height: 256px; | ||
|
||
padding: 32px; | ||
|
||
background: $wh-color; | ||
border-radius: $medium-radius; | ||
|
||
&__category { | ||
@include goodCategory; | ||
} | ||
|
||
&__name { | ||
@include goodName; | ||
} | ||
|
||
&__container { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
&__price { | ||
@include goodPrice; | ||
} | ||
|
||
&__icon { | ||
@include goodIcon; | ||
} | ||
|
||
&__button { | ||
@include smallFont; | ||
|
||
width: 64px; | ||
height: 56px; | ||
|
||
color: $main-color; | ||
background-color: $wh-color; | ||
|
||
letter-spacing: $small-spacing; | ||
|
||
text-transform: uppercase; | ||
outline: none; | ||
border: 1px solid rgba(0, 0, 0, 0.1); | ||
border-radius: $small-radius; | ||
|
||
&:hover { | ||
color: $wh-color; | ||
background: $main-color; | ||
border: none; | ||
} | ||
} | ||
} | ||
|
||
@media screen and (max-width: 400px) { | ||
.good { | ||
padding: 16px; | ||
height: 160px; | ||
|
||
&__name { | ||
font-size: 20px; | ||
line-height: 20px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
&__category { | ||
font-size: 12px; | ||
margin: 0; | ||
} | ||
|
||
&__price { | ||
font-size: 40px; | ||
line-height: 40px; | ||
} | ||
|
||
&__icon { | ||
font-size: 20px; | ||
line-height: 20px; | ||
margin: 8px 3px 0 0; | ||
} | ||
} | ||
} |
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,58 @@ | ||
import React, { useState } from 'react'; | ||
import { CurrentGood } from '../CurrentGood/CurrentGood'; | ||
import '../GoodsList/goodsList.scss'; | ||
import { Loader } from '../Loader/Loader'; | ||
import { ModalWindow } from '../ModalWindow/ModalWindow'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const GoodsList = ({data}) => { | ||
const [isOpenWindow, setIsOpenWindow] = useState(false); | ||
const [windowData, setWindowData] = useState(null); | ||
|
||
const minValue = () => { | ||
let min = data[0].price; | ||
|
||
for (let i = 0; i < data.length; i++) { | ||
if (data[i].price < min) { | ||
min = data[i].price; | ||
setWindowData(data[i]); | ||
} | ||
} | ||
setIsOpenWindow(true); | ||
} | ||
|
||
if (data.length === 0) { | ||
return ( | ||
<Loader /> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{isOpenWindow && <ModalWindow data={windowData} reset={setIsOpenWindow} />} | ||
<div className="goods"> | ||
{ | ||
data.map(item => ( | ||
<CurrentGood | ||
key={item.id} | ||
good={item} | ||
setIsOpen={setIsOpenWindow} | ||
setData={setWindowData} | ||
/> | ||
)) | ||
} | ||
</div> | ||
<button | ||
type="button" | ||
className="goods__button" | ||
onClick={minValue} | ||
> | ||
Buy cheapest | ||
</button> | ||
</> | ||
); | ||
} | ||
|
||
GoodsList.propTypes = { | ||
data: PropTypes.array.isRequired, | ||
} |
Oops, something went wrong.