+
diff --git a/src/Breed-Search b/src/Breed-Search new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/Breed-Search @@ -0,0 +1 @@ + diff --git a/src/Dog-Breed-Search b/src/Dog-Breed-Search new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/Dog-Breed-Search @@ -0,0 +1 @@ + diff --git a/src/components/Api.js b/src/components/Api.js new file mode 100644 index 0000000..802b7c6 --- /dev/null +++ b/src/components/Api.js @@ -0,0 +1,7 @@ +const BASE_URL = 'https://dog.ceo/api'; + +export async function fetchImagesByBreed(breed) { + const response = await fetch(`${BASE_URL}/breed/${breed}/images/random/10`); + const data = await response.json(); + return data.message; +} \ No newline at end of file diff --git a/src/components/App.css b/src/components/App.css new file mode 100644 index 0000000..6eb629a --- /dev/null +++ b/src/components/App.css @@ -0,0 +1,179 @@ +body, h1, h2, p { + margin: 0; + padding: 0; +} + +/* Set a background color for the whole app and use a default font */ +body { + background-color: #f5f5f5; + font-family: Arial, sans-serif; +} + +h1{ + height: 121px; + height: 24px; +} + +/* Header styling */ +.App-header { + color: black; + text-align: center; + padding: 1rem 0; + margin-right: 31%; + margin-top: 2%; +} + +/* Main content area styling */ +.App-main { + max-width: 800px; + margin: 0 auto; + padding: 2rem; +} + +/* Styling for input and button elements */ +input{ + padding: 0.5rem 1rem; + border: none; + font-size: 20px; + width: 630px; + height: 36px; + margin-left: 10px; + margin-bottom: 20px; + +} +button { + padding: 0.5rem 1rem; + border: none; + font-size: 16px; + width: 105px; + height: 55px; +} + +/* Button styling */ +button { + background-color: #333; + color: white; + cursor: pointer; + transition: background-color 0.3s ease; +} + +/* Button hover effect */ +button:hover { + background-color: #555; +} + +/* Image gallery layout */ +.images { + display: flex; + justify-content: space-evenly,flex-start; + flex-wrap: wrap; + gap: 1rem; +} + +/* Styling for individual image containers */ +.image { + flex: 0 0 calc(20% - 1rem); + padding: .5rem; + text-align: center; + position: relative; + overflow: hidden; + height: 160px; + width: 160px; + + /* Add a light gray background color */ +} + +/* Position the favorite button at the bottom of the container */ +.image button { + position: absolute; + left: 75%; + bottom: 5%; + color: white; + height: 30px; + width: 30px; + cursor: pointer; + +} + +/* Ensure images cover the entire box */ +.image img { + width: 100%; + height: 100%; + object-fit: cover; +} + +/* Center align text in the header */ +.App-header h1 { + margin: 0; +} + +/* Media query for smaller screens */ +@media (max-width: 600px) { + .images { + flex-direction: column; + } + + .image { + flex: 0 0 100%; + } +} + +/* Favorites section styling */ +.favorites { + margin-top: 2rem; + margin-bottom: 2rem; +} + +/* Image gallery layout for favorites */ +.favorite-images { + display: flex; + justify-content: space-evenly,flex-start; + flex-wrap: wrap; + margin-top: 20px; +} + +.favorites .favorite-image img{ + border-radius: 3%; +} + +/* Styling for individual image containers for favorites */ +.favorites .image { + padding: 1rem; + border: 1px solid #ddd; + text-align: center; + background-color: white; + position: relative; + overflow: hidden; + background-color: #f9f9f9; + /* Add a light gray background color */ + +} + +.favorites .favorite-image button{ + position: relative; + right: 20%; + bottom: 5%; + height: 30px; + width: 30px; + +} + +/* Position the favorite button at the bottom of the container for favorites */ +.favorites .image button { + position: absolute; + bottom: 1rem; + left: 50%; + color: white; + border: none; + cursor: pointer; + +} + + +/* Ensure images cover the entire box for favorites */ +.favorites .image img { + width: 100%; + height: 100%; + object-fit: cover; + +} \ No newline at end of file diff --git a/src/components/App.js b/src/components/App.js new file mode 100644 index 0000000..40c8305 --- /dev/null +++ b/src/components/App.js @@ -0,0 +1,53 @@ +import React, { useState } from 'react'; +import './App.css'; +import SearchInput from './SearchInput'; +import ImageGallery from './ImageGalary'; +import Favorites from './Favourites'; +import { fetchImagesByBreed } from './Api'; + +function App() { + const [images, setImages] = useState([]); + const [favorites, setFavorites] = useState([]); + + const handleSearch = async (breed) => { + try { + const newImages = await fetchImagesByBreed(breed); + console.log('API response:', newImages); + + if (Array.isArray(newImages)) { + setImages(newImages); + } else { + console.error('Invalid API response:', newImages); + } + } catch (error) { + console.error('Error fetching images:', error); + } + }; + + const handleFavorite = (imageUrl) => { + if (!favorites.includes(imageUrl)) { + setFavorites([...favorites, imageUrl]); + } + }; + + const handleUnfavorite = (imageUrl) => { + const newFavorites = favorites.filter((url) => url !== imageUrl); + setFavorites(newFavorites); + }; + + return ( +