Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 8 commits into
base: feedback
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_EDAMAM_APP_ID = 84f7612f
VITE_EDAMAM_APP_KEY = fc5d604e2641548209bdfaaec1e34129
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-24ddc0f5d75046c5622901739e7c5dd533143b0c8e959d652212380cedb1ea36.svg)](https://classroom.github.com/a/nEc54K2B)
# React API project

### In this project you will be using React to create a project using an API for content.
Expand Down
Binary file added images/bg1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>API project</title>
<link rel="stylesheet" href="src/styles.css" />
</head>
<body>
<div id="root"></div>
Expand Down
157 changes: 156 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.6.8",
"history": "^5.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.0"
},
"devDependencies": {
"@types/react": "^18.2.66",
Expand Down
79 changes: 79 additions & 0 deletions pages/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { useState } from "react";
import { Link } from "react-router-dom";

import axios from "axios";
import "../src/App.css"; // Import CSS file for styling

const HomePage = () => {
const [ingredients, setIngredients] = useState("");
const [recipes, setRecipes] = useState([]);
const [loading, setLoading] = useState(false);

const handleInputChange = (event) => {
setIngredients(event.target.value);
};

const handleSubmit = async (event) => {
event.preventDefault();
setLoading(true);

try {
const response = await axios.get("https://api.edamam.com/search", {
params: {
q: ingredients,
app_id: import.meta.env.VITE_EDAMAM_APP_ID,
app_key: import.meta.env.VITE_EDAMAM_APP_KEY,
},
});

if (response.data.hits) {
setRecipes(response.data.hits.map((hit) => hit.recipe));
} else {
// Handle case when no recipes are found
setRecipes([]);
}
} catch (error) {
console.error("Error fetching recipes:", error);
}

setLoading(false);
};

return (
<div className="container">
<div className="search-container">
<h1>Meal Planner</h1>
<form onSubmit={handleSubmit}>
<input
type="text"
value={ingredients}
onChange={handleInputChange}
placeholder="Enter ingredients (comma separated)"
/>
<button type="submit" disabled={loading}>
Search
</button>
</form>
{loading && <p>Loading...</p>}
</div>
<div className="recipe-container">
{recipes.map((recipe) => (
<div className="recipe-box" key={recipe.uri}>
<h2>{recipe.label}</h2>
<img src={recipe.image} alt={recipe.label} />
<ul>
{recipe.ingredients.map((ingredient, index) => (
<li key={index}>{ingredient.text}</li>
))}
</ul>
<a href={recipe.url} target="_blank" rel="noopener noreferrer">
View Recipe
</a>
</div>
))}
</div>
</div>
);
};

export default HomePage;
13 changes: 13 additions & 0 deletions pages/NotFound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// NotFound.js
import React from "react";

const NotFound = () => {
return (
<div>
<h1>404 🙇‍♂️- Page Not Found</h1>
<p>OOPS!The page you are looking for does not exist🙅‍♂️.</p>
</div>
);
};

export default NotFound;
Loading