Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima-Semenov committed Feb 16, 2021
1 parent 940229c commit fb15098
Show file tree
Hide file tree
Showing 30 changed files with 1,782 additions and 173 deletions.
974 changes: 965 additions & 9 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{
"name": "modal",
"homepage": "https://Dima-Semenov.github.io/goods",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.7.1",
"classnames": "^2.2.6",
"gh-pages": "^3.1.0",
"node-sass": "^4.14.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2",
"web-vitals": "^1.1.0"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
Expand Down
25 changes: 0 additions & 25 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,9 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions public/robots.txt

This file was deleted.

38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

25 changes: 0 additions & 25 deletions src/App.js

This file was deleted.

26 changes: 26 additions & 0 deletions src/App.jsx
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>
);
}
13 changes: 13 additions & 0 deletions src/App.scss
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;
}
}
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

40 changes: 40 additions & 0 deletions src/Components/CurrentGood/CurrentGood.jsx
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,
}
86 changes: 86 additions & 0 deletions src/Components/CurrentGood/currentGood.scss
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;
}
}
}
58 changes: 58 additions & 0 deletions src/Components/GoodsList/GoodsList.jsx
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,
}
Loading

0 comments on commit fb15098

Please sign in to comment.