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 }) => (