diff --git a/src/components/App.jsx b/src/components/App.jsx index 9c5b300..c0f24c3 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -3,12 +3,14 @@ import Searchbar from './Searchbar'; import { ImageGallery } from './ImageGallery'; import ImagePortalWelcome from './ImagePortalWelcome'; import { LoadMoreBtn } from './Button'; +import { SearchResultInfo } from './SearchResultInfo'; -import { Container, Row, Col, Alert } from 'react-bootstrap'; +import { Container, Row } from 'react-bootstrap'; import axios from 'axios'; import 'bootstrap/dist/css/bootstrap.min.css'; +import { Loader } from './Loader'; const API_KEY = '41006597-e52c63fe5093395ccafd50f48'; @@ -22,11 +24,16 @@ class App extends Component { images: [], searchQuery: '', activePage: 1, + isLoading: false, }; } getImages = async (searchQuery, activePage) => { try { + this.setState({ + isLoading: true, + }); + const params = { q: searchQuery, page: activePage, @@ -51,7 +58,9 @@ class App extends Component { } catch (error) { console.error('Error searching for images:', error.message); } finally { - // for Loader + this.setState({ + isLoading: false, + }); } }; @@ -63,32 +72,24 @@ class App extends Component { this.setState({ activePage: nextPage }); }; - componentDidUpdate(prevProps, prevState) { + componentDidUpdate(prevProps) { if (prevProps.searchQuery !== this.props.searchQuery) { this.getImages(this.props.searchQuery); } } render() { - const { images, searchQuery } = this.state; + const { images, searchQuery, isLoading } = this.state; return ( <> + {isLoading && } {images.length > 0 ? ( <> - - - - - Showing results for - {searchQuery} - - - - + diff --git a/src/components/Loader.jsx b/src/components/Loader.jsx index f688dfa..9ee2a08 100644 --- a/src/components/Loader.jsx +++ b/src/components/Loader.jsx @@ -2,8 +2,22 @@ import { Spinner } from 'react-bootstrap'; export const Loader = () => { return ( - - Loading... - +
+ + Loading... + +
); };