|
1 |
| -import {useEffect, useState} from 'react'; |
| 1 | +import { |
| 2 | + useEffect, |
| 3 | + useState |
| 4 | +} from 'react'; |
2 | 5 |
|
3 | 6 | // import from material/ui
|
4 |
| -import {Box} from '@material-ui/core' |
| 7 | +import { |
| 8 | + Box |
| 9 | +} from '@material-ui/core' |
5 | 10 |
|
6 | 11 | // components
|
7 | 12 | import Navbar from './Components/Navbar'
|
8 | 13 | import BreadCrumb from './Components/BreadCrumb';
|
9 | 14 | import Image from './Components/Image'
|
10 | 15 | import SnackBar from './Components/SnackBar';
|
11 | 16 |
|
12 |
| -import {getImages} from './Services/api' |
| 17 | +import { |
| 18 | + getImages |
| 19 | +} from './Services/api' |
13 | 20 |
|
14 | 21 | function App() {
|
15 |
| - const [data, setData] = useState([]); |
16 |
| - const[count, setCount] = useState(10); |
17 |
| - const[text , setText] = useState("mountains"); |
18 |
| - const[open , toggleSnack] = useState(false); |
19 |
| - |
20 |
| - useEffect( ()=>{ |
21 |
| - |
22 |
| - if(count<3 || count>200){ |
23 |
| - toggleSnack(true); |
24 |
| - return; |
25 |
| - } |
26 |
| - |
27 |
| - toggleSnack(false); |
28 |
| - |
29 |
| - getImages(text,count).then( response => { |
30 |
| - setData(response.data.hits) |
31 |
| - // console.log(response.data.hits); |
32 |
| - }) |
33 |
| - } , [text,count]) |
34 |
| - |
35 |
| - |
36 |
| - const onTextChange = (text)=>{ |
37 |
| - setText(text); |
38 |
| - } |
39 |
| - |
40 |
| - |
41 |
| - const onCountChange = (count)=>{ |
42 |
| - setCount(count); |
43 |
| - } |
44 |
| - |
45 |
| - return ( |
46 |
| - <Box> |
47 |
| - <Navbar /> |
48 |
| - <BreadCrumb onTextChange= {onTextChange} onCountChange ={onCountChange}/> |
49 |
| - <Image data = {data} /> |
50 |
| - <SnackBar open={open} toggleSnack={toggleSnack}/> |
51 |
| - </Box> |
52 |
| - ); |
| 22 | + const [data, setData] = useState([]); |
| 23 | + const [count, setCount] = useState(10); |
| 24 | + const [text, setText] = useState("mountains"); |
| 25 | + const [open, toggleSnack] = useState(false); |
| 26 | + |
| 27 | + useEffect(() => { |
| 28 | + |
| 29 | + if (count < 3 || count > 200) { |
| 30 | + toggleSnack(true); |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + toggleSnack(false); |
| 35 | + |
| 36 | + getImages(text, count).then(response => { |
| 37 | + setData(response.data.hits) |
| 38 | + // console.log(response.data.hits); |
| 39 | + }) |
| 40 | + }, [text, count]) |
| 41 | + |
| 42 | + |
| 43 | + const onTextChange = (text) => { |
| 44 | + setText(text); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + const onCountChange = (count) => { |
| 49 | + setCount(count); |
| 50 | + } |
| 51 | + |
| 52 | + return ( |
| 53 | + <Box > |
| 54 | + <Navbar / > |
| 55 | + <BreadCrumb onTextChange = { |
| 56 | + onTextChange |
| 57 | + } |
| 58 | + onCountChange = { |
| 59 | + onCountChange |
| 60 | + } |
| 61 | + /> |
| 62 | + <Image data = { |
| 63 | + data |
| 64 | + } |
| 65 | + /> |
| 66 | + <SnackBar open = { |
| 67 | + open |
| 68 | + } |
| 69 | + toggleSnack = { |
| 70 | + toggleSnack |
| 71 | + } |
| 72 | + /> |
| 73 | + </Box> |
| 74 | + ); |
53 | 75 | }
|
54 | 76 |
|
55 | 77 | export default App;
|
0 commit comments