-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Izzet Yusufov
authored and
Izzet Yusufov
committed
Aug 1, 2023
1 parent
42cfbd8
commit 4a00861
Showing
5 changed files
with
82 additions
and
24 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
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 +1,11 @@ | ||
// styles go here | ||
.red--item { | ||
color: red; | ||
} | ||
|
||
.blue--item { | ||
color: blue; | ||
} | ||
|
||
.green--item { | ||
color: green; | ||
} |
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,27 +1,70 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import './App.scss'; | ||
import { GoodsList } from './GoodsList'; | ||
import { Good } from './types/Good'; | ||
import { getAll, get5First, getRedGoods } from './api/goods'; | ||
|
||
// import { getAll, get5First, getRed } from './api/goods'; | ||
// or | ||
// import * as goodsAPI from './api/goods'; | ||
enum ServerRequest { | ||
AllGoods = 'ALL', | ||
FiveFirst = 'FiveFirst', | ||
OnlyRed = 'OnlyRed', | ||
} | ||
|
||
export const App: React.FC = () => ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
export const App: React.FC = () => { | ||
const [goods, setGoods] = useState<Good[]>([]); | ||
const [ | ||
serverReqeust, | ||
setServerReqeust, | ||
] = useState<ServerRequest | null>(null); | ||
|
||
<button type="button" data-cy="all-button"> | ||
Load all goods | ||
</button> | ||
useEffect(() => { | ||
if (serverReqeust === ServerRequest.AllGoods) { | ||
getAll().then((goodsRequest: Good[]) => { | ||
setGoods(goodsRequest); | ||
}); | ||
} | ||
|
||
<button type="button" data-cy="first-five-button"> | ||
Load 5 first goods | ||
</button> | ||
if (serverReqeust === ServerRequest.FiveFirst) { | ||
get5First().then((goodsRequest: Good[]) => { | ||
setGoods(goodsRequest); | ||
}); | ||
} | ||
|
||
<button type="button" data-cy="red-button"> | ||
Load red goods | ||
</button> | ||
if (serverReqeust === ServerRequest.OnlyRed) { | ||
getRedGoods().then((goodsRequest: Good[]) => { | ||
setGoods(goodsRequest); | ||
}); | ||
} | ||
}, [serverReqeust]); | ||
|
||
<GoodsList goods={[]} /> | ||
</div> | ||
); | ||
return ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
|
||
<button | ||
type="button" | ||
data-cy="all-button" | ||
onClick={() => setServerReqeust(ServerRequest.AllGoods)} | ||
> | ||
Load all goods | ||
</button> | ||
|
||
<button | ||
type="button" | ||
data-cy="first-five-button" | ||
onClick={() => setServerReqeust(ServerRequest.FiveFirst)} | ||
> | ||
Load 5 first goods | ||
</button> | ||
|
||
<button | ||
type="button" | ||
data-cy="red-button" | ||
onClick={() => setServerReqeust(ServerRequest.OnlyRed)} | ||
> | ||
Load red goods | ||
</button> | ||
{serverReqeust !== null && <GoodsList goods={goods} />} | ||
</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
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