diff --git a/package.json b/package.json
index 3fe08e488..af87fd478 100755
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"@mate-academy/cypress-tools": "^1.0.4",
"@mate-academy/eslint-config-react": "0.0.7",
"@mate-academy/eslint-config-react-typescript": "^1.0.1",
- "@mate-academy/scripts": "^1.2.3",
+ "@mate-academy/scripts": "^1.2.8",
"@mate-academy/students-ts-config": "*",
"@mate-academy/stylelint-config": "*",
"@types/node": "^17.0.23",
diff --git a/src/App.scss b/src/App.scss
index dc81a3449..b516d8066 100644
--- a/src/App.scss
+++ b/src/App.scss
@@ -1 +1,4 @@
// styles go here
+iframe {
+ display: none;
+}
diff --git a/src/App.tsx b/src/App.tsx
index 2cf5239da..51c98b664 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,27 +1,67 @@
-import React from 'react';
+/* eslint-disable max-len */
+/* eslint-disable implicit-arrow-linebreak */
+import React, { useMemo, useState } from 'react';
import './App.scss';
import { GoodsList } from './GoodsList';
-// import { getAll, get5First, getRed } from './api/goods';
+import { getAll, get5First, getRedGoods } from './api/goods';
+import { Good } from './types/Good';
// or
// import * as goodsAPI from './api/goods';
-export const App: React.FC = () => (
-
-
Dynamic list of Goods
+export const App: React.FC = () => {
+ const [preparedGoods, setPreparedGoods] = useState([]);
+ const [errorMessage, setErrorMessage] = useState('');
-
+ const onLoad = useMemo(() => () => getAll()
+ .then(setPreparedGoods)
+ .catch(err => setErrorMessage(err)),
+ []);
-
+ const onLoadFirstFive = useMemo(() => () => get5First()
+ .then(setPreparedGoods)
+ .catch(err => setErrorMessage(err)),
+ []);
-
+ const onLoadRedOnes = useMemo(() => () => getRedGoods()
+ .then(setPreparedGoods)
+ .catch(err => setErrorMessage(err)),
+ []);
-
-
-);
+ return (
+
+
Dynamic list of Goods
+
+
+
+
+
+
+
+ {errorMessage
+ ? (
+
{errorMessage}
+ ) : (
+
+ )}
+
+ );
+};
diff --git a/src/GoodsList.tsx b/src/GoodsList.tsx
index b56a4331e..45e78feef 100644
--- a/src/GoodsList.tsx
+++ b/src/GoodsList.tsx
@@ -8,7 +8,11 @@ type Props = {
export const GoodsList: React.FC = ({ goods }) => (
{goods.map(good => (
- -
+
-
{good.name}
))}
diff --git a/src/api/goods.ts b/src/api/goods.ts
index f0d1659f8..ab90777d7 100644
--- a/src/api/goods.ts
+++ b/src/api/goods.ts
@@ -10,10 +10,20 @@ export function getAll(): Promise {
export const get5First = () => {
return getAll()
- .then(goods => goods); // sort and get the first 5
+ .then(goods => {
+ const normalizedGoods = goods
+ .sort((good1, good2) => good1.name.localeCompare(good2.name))
+ .splice(0, 5);
+
+ return normalizedGoods;
+ });
};
export const getRedGoods = () => {
return getAll()
- .then(goods => goods); // get only red
+ .then(goods => {
+ const normalizedGoods = goods.filter(good => good.color === 'red');
+
+ return normalizedGoods;
+ });
};