Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Breed-Search
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/Dog-Breed-Search
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 7 additions & 0 deletions src/components/Api.js
Original file line number Diff line number Diff line change
@@ -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;
}
179 changes: 179 additions & 0 deletions src/components/App.css
Original file line number Diff line number Diff line change
@@ -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;

}
53 changes: 53 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="App">
<header className="App-header">
<h1>Dog Breeds</h1>
</header>
<main className="App-main">
<SearchInput onSearch={handleSearch} />
<ImageGallery images={images} Favorite={handleFavorite} />
<hr/>
<Favorites favorites={favorites} Unfavorite={handleUnfavorite} />
</main>
</div>
);
}

export default App;
8 changes: 8 additions & 0 deletions src/components/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
20 changes: 20 additions & 0 deletions src/components/Favourites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { IoIosHeart } from "react-icons/io";

function Favorites({ favorites, Unfavorite }) {
return (
<div className="favorites">
<h2>Favorites</h2>
<div className="favorite-images">
{favorites.map((imageUrl) => (
<div key={imageUrl} className="favorite-image">
<img src={imageUrl} alt="Favorite Dog" height="128px" width="128px" />
<button onClick={() => Unfavorite(imageUrl)}><IoIosHeart color="red"/></button>
</div>
))}
</div>
</div>
);
}

export default Favorites;
18 changes: 18 additions & 0 deletions src/components/ImageGalary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { IoIosHeartEmpty } from "react-icons/io";

function ImageGallery({ images, Favorite }) {
return (
<div className="images">
{images.map((imageUrl) => (
<div key={imageUrl} className="image">
<img src={imageUrl} alt="Dog"/>
<button onClick={(e) => {
Favorite(imageUrl)}}><IoIosHeartEmpty/></button>
</div>
))}
</div>
);
}

export default ImageGallery;
23 changes: 23 additions & 0 deletions src/components/SearchInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useState } from 'react';

function SearchInput({ onSearch }) {
const [breed, setBreed] = useState('');

const handleSearch = () => {
onSearch(breed);
};

return (
<div>
<input
type="text"
placeholder="Enter A Breed ?"
value={breed}
onChange={(e) => setBreed(e.target.value)}
/>
<button onClick={handleSearch}>&#128269;Search</button>
</div>
);
}

export default SearchInput;
13 changes: 13 additions & 0 deletions src/components/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
17 changes: 17 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
5 changes: 5 additions & 0 deletions src/components/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';