-
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
AndriiYelieva
committed
Aug 1, 2023
1 parent
42cfbd8
commit 5625918
Showing
6 changed files
with
126 additions
and
67 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,81 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import './App.scss'; | ||
|
||
import { GoodsList } from './GoodsList'; | ||
|
||
// import { getAll, get5First, getRed } from './api/goods'; | ||
// or | ||
// import * as goodsAPI from './api/goods'; | ||
import { | ||
get5First, | ||
getAll, | ||
getRedGoods, | ||
} from './api/goods'; | ||
import { Good } from './types/Good'; | ||
import { Status } from './service/Status'; | ||
|
||
export const App: React.FC = () => { | ||
const [goods, setGoods] = useState<Good[]>([]); | ||
const [filter, setFilter] = useState(Status.ALL); | ||
|
||
useEffect(() => { | ||
getAll().then(setGoods); | ||
}, []); | ||
|
||
const handleButtonClick = (status: Status): void => { | ||
if (status === filter) { | ||
return; | ||
} | ||
|
||
setFilter(status); | ||
|
||
switch (status) { | ||
case Status.ALL: | ||
getAll().then(setGoods); | ||
break; | ||
|
||
case Status.FIRST5: | ||
get5First().then(setGoods); | ||
break; | ||
|
||
case Status.RED: | ||
getRedGoods().then(setGoods); | ||
break; | ||
|
||
default: | ||
getAll().then(setGoods); | ||
} | ||
}; | ||
|
||
export const App: React.FC = () => ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
return ( | ||
<div className="App"> | ||
<h1>Dynamic list of Goods</h1> | ||
|
||
<button type="button" data-cy="all-button"> | ||
Load all goods | ||
</button> | ||
<button | ||
type="button" | ||
data-cy="all-button" | ||
onClick={() => { | ||
handleButtonClick(Status.ALL); | ||
}} | ||
> | ||
Load all goods | ||
</button> | ||
|
||
<button type="button" data-cy="first-five-button"> | ||
Load 5 first goods | ||
</button> | ||
<button | ||
type="button" | ||
data-cy="first-five-button" | ||
onClick={() => handleButtonClick(Status.FIRST5)} | ||
> | ||
Load 5 first goods | ||
</button> | ||
|
||
<button type="button" data-cy="red-button"> | ||
Load red goods | ||
</button> | ||
<button | ||
type="button" | ||
data-cy="red-button" | ||
onClick={() => handleButtonClick(Status.RED)} | ||
> | ||
Load red goods | ||
</button> | ||
|
||
<GoodsList goods={[]} /> | ||
</div> | ||
); | ||
<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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Status { | ||
ALL = 'All', | ||
RED = 'Red', | ||
FIRST5 = 'First5', | ||
} |