Skip to content

Commit b589651

Browse files
+
1 parent 7a7400f commit b589651

File tree

8 files changed

+48
-15
lines changed

8 files changed

+48
-15
lines changed

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@testing-library/react": "^12.1.4",
99
"@testing-library/user-event": "^13.5.0",
1010
"nanoid": "^4.0.2",
11+
"prop-types": "^15.8.1",
1112
"react": "^18.1.0",
1213
"react-dom": "^18.1.0",
1314
"react-loader-spinner": "^5.3.4",

src/components/App.jsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import React from 'react';
12
import { Component } from 'react';
23
import { ToastContainer } from 'react-toastify';
34
import Searchbar from './searchbar/searchbar';
4-
import api from 'components/service-api/pixabay-api';
5+
import api from './service-api/pixabay-api';
56
import { toast } from 'react-toastify';
6-
import ImageGallery from 'components/imageGallery/imageGallery';
7-
import Button from 'components/button/button';
8-
import Loader from 'components/loader/loader';
9-
import Modal from 'components/modal/modal';
7+
import ImageGallery from './imageGallery/imageGallery';
8+
import Button from './button/button';
9+
import Loader from './loader/loader';
10+
import Modal from './modal/modal';
1011
export class App extends Component {
1112
state = {
1213
searchQuery: '',
@@ -17,6 +18,7 @@ export class App extends Component {
1718
showLoader: false,
1819
showModal: false,
1920
selectedImage: null,
21+
galleryRef: React.createRef(),
2022
}// we got state 'searchQuery' from 'searchbar.js' (searchQueryOriginal=searchQuery)
2123

2224
async componentDidUpdate(prevProps, prevState) {
@@ -37,7 +39,7 @@ export class App extends Component {
3739
showLoadMore: data.totalHits > 12 * currentPage,
3840
page: currentPage
3941
});
40-
!data.totalHits ? toast.error("No results found. Please try again!") : toast.success(`Hooray! We found ${data.totalHits} images`);
42+
!data.totalHits && toast.error("No results found. Please try again!");// : toast.success(`Hooray! We found ${data.totalHits} images`);
4143
nextPage >= totalPage && toast.warning("We're sorry, but you've reached the end of search results!");
4244
} catch (error) {
4345
this.setState({ error });

src/components/button/button.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import PropTypes from 'prop-types';
2+
13
const Button = ({ children, handleClick }) => {
4+
25
return (
36
<div className="btn-wrapper">
47
<button
@@ -10,4 +13,8 @@ const Button = ({ children, handleClick }) => {
1013
)
1114
}
1215

13-
export default Button;
16+
export default Button;
17+
18+
Button.propTypes = {
19+
handleClick: PropTypes.func,
20+
}
+10-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
import PropTypes from 'prop-types';
12
import ImageGalleryItem from 'components/imageGalleryItem/imageGalleryItem';
23

3-
const ImageGallery = ({ arrayResults, onOpenModal, getFilmId }) => {
4-
4+
const ImageGallery = ({ arrayResults, onOpenModal, ref }) => {
55
return (
6-
<ul className="ImageGallery">
6+
<ul className="ImageGallery" id='gallery'>
77
{arrayResults.map(image => {
88
return (
99
<ImageGalleryItem
1010
key={image.id}
1111
imageId={image.id}
1212
imageWeb={image.webformatURL}
1313
onOpenModal={onOpenModal}
14-
getFilmId={getFilmId}
1514
/>
1615
)
1716
})}
1817
</ul>
1918
)
2019
}
2120

22-
export default ImageGallery;
21+
export default ImageGallery;
22+
23+
ImageGallery.propTypes = {
24+
arrayResults: PropTypes.array,
25+
onOpenModal: PropTypes.func,
26+
key: PropTypes.number,
27+
}

src/components/imageGalleryItem/imageGalleryItem.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const ImageGalleryItem = ({ imageWeb, imageId, onOpenModal, getFilmId }) => {
1+
import PropTypes from 'prop-types';
2+
3+
const ImageGalleryItem = ({ imageWeb, imageId, onOpenModal }) => {
24
const handleClick = () => {
35
onOpenModal(imageId)
46
};
@@ -14,3 +16,9 @@ const ImageGalleryItem = ({ imageWeb, imageId, onOpenModal, getFilmId }) => {
1416
};
1517

1618
export default ImageGalleryItem;
19+
20+
ImageGalleryItem.propTypes = {
21+
imageWeb: PropTypes.string,
22+
onOpenModal: PropTypes.func,
23+
imageId: PropTypes.number,
24+
}

src/components/modal/modal.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from "react";
22
import { createPortal } from "react-dom";
3-
3+
import PropTypes from 'prop-types';
44
class Modal extends Component {
55
modalRoot = document.querySelector('#root-modal');
66
// { children, onBackdropClose, onKeydownClose } -->>>>props
@@ -20,4 +20,8 @@ class Modal extends Component {
2020
)
2121
}
2222
}
23-
export default Modal;
23+
export default Modal;
24+
25+
Modal.propTypes = {
26+
onSubmit: PropTypes.func,
27+
}

src/components/searchbar/searchbar.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component } from 'react';
22
import '../../index.css'
33
import { toast } from 'react-toastify';
44
import 'react-toastify/dist/ReactToastify.css';
5+
import PropTypes from 'prop-types';
56

67
class Searchbar extends Component {
78
state = {
@@ -45,3 +46,7 @@ class Searchbar extends Component {
4546
}
4647
}
4748
export default Searchbar;
49+
50+
Searchbar.propTypes = {
51+
onSubmit: PropTypes.func
52+
}

0 commit comments

Comments
 (0)