Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Neel317 committed Oct 19, 2023
2 parents fab526c + 4d7975d commit d73e142
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 24 deletions.
7 changes: 4 additions & 3 deletions Code/frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ class App extends Component {
const cuis = formDict["cuisine"];
const cook_time = formDict["time_to_cook"];
const budget = formDict["budget"];
this.getRecipeDetails(items, cuis, cook_time, budget);
const pref = formDict["food_pref"];
this.getRecipeDetails(items, cuis, cook_time, budget, pref);
// alert(typeof(ingredientsInput["cuisine"]));
};

getRecipeDetails = async (ingredient, cuis, cook_time, budget) => {
getRecipeDetails = async (ingredient, cuis, cook_time, budget, pref) => {
console.log(ingredient, cuis, cook_time, budget);
try {
const response = await recipeDB
.get(
`/recipes?CleanedIngredients=${ingredient}&Cuisine=${cuis}&budget=${budget}&TotalTimeInMins=${cook_time}`,
`/recipes?CleanedIngredients=${ingredient}&Cuisine=${cuis}&budget=${budget}&TotalTimeInMins=${cook_time}&typeOfDiet=${pref}`,
)
.catch((err) => {
console.log(err, err.message);
Expand Down
21 changes: 21 additions & 0 deletions Code/frontend/src/components/AddRecipeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Form extends Component {
dict["recipe_time"] = document.getElementById("recipe_time").value;
dict["recipe_url"] = document.getElementById("recipe_url").value;
dict["recipe_budget"] = document.getElementById("recipe_budget").value;
dict["food_pref"] = document.getElementById("food_pref").value;
console.log(dict);

let all_val_filled = [];
Expand Down Expand Up @@ -166,6 +167,26 @@ class Form extends Component {
</div>
</div>
</div>

<div className="row pb-1">
<div className="input-group col-lg-4 bg-danger flexer">
<label className="sideLabel"> Recipe Time: </label>
<div className="input-group-append" style={{ width: "66%" }}>
<select
name="time_to_cook"
id="food_pref"
className="form-input"
style={{ width: "100%" }}
>
<option value="Vegetarian">Vegetarian</option>
<option value="Non-Vegetarian">Non-Vegetarian</option>
<option value="Vegan">Vegan</option>
</select>
{/* <input type="text" id="recipe_time" /> */}
</div>
</div>
</div>

<div className="row pb-1">
<div className="input-group col-lg-4 bg-danger flexer">
<label className="sideLabel"> Recipe URL: </label> <br />
Expand Down
38 changes: 21 additions & 17 deletions Code/frontend/src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,12 @@ class Form extends Component {
searchRecipe = async () => {
const budget = document.getElementById("budget").value;
const time = document.getElementById("time_to_cook").value;

if (isNaN(budget) || budget <= 0) {
alert("Budget should be a positive number");
return;
}

if (isNaN(time) || time <= 0) {
alert("Time to cook should be a positive number");
return;
}
const pref = document.getElementById("food_pref").value;
console.log("PREFERENCE", pref);

const response = await recipeDB
.get(
`/recipes?CleanedIngredients=${this.state.ingredients}&Cuisine=${this.state.ingredients}&budget=${budget}&TotalTimeInMins=${time}`,
`/recipes?CleanedIngredients=${this.state.ingredients}&Cuisine=${this.state.ingredients}&budget=${budget}&TotalTimeInMins=${time}&typeOfDiet=${pref}`,
)
.catch((err) => {
console.log(err, err.message);
Expand Down Expand Up @@ -151,24 +143,19 @@ class Form extends Component {
() => console.log(this.state),
);

if (this.state.cuisine.trim() === "") {
alert("Cuisine cannot be empty");
return;
}

event.preventDefault();
var dict = {};
dict["ingredient"] = this.state.ingredients;
dict["cuisine"] = document.getElementById("cuisine").value;
dict["time_to_cook"] = document.getElementById("time_to_cook").value;
dict["budget"] = document.getElementById("budget").value;
dict["time_to_cook"] = document.getElementById("time_to_cook").value;
dict["food_pref"] = document.getElementById("food_pref").value;

console.log(dict);

this.props.sendFormData(dict);
document.getElementById("cuisine").value = "";
document.getElementById("time_to_cook").value = "";

// this.searchRecipe();
};
Expand Down Expand Up @@ -229,6 +216,23 @@ class Form extends Component {
</select>
</div>
</div>

<div className="row pb-1">
<div className="input-group col-lg-4 bg-danger text-white flexer-new">
<label className="sideLabel-new">Preference:</label> <br />
<select
style={{ width: "auto" }}
name="time_to_cook"
id="food_pref"
className="form-input"
>
<option value="Vegetarian">Vegetarian</option>
<option value="Non-Vegetarian">Non-Vegetarian</option>
<option value="Vegan">Vegan</option>
</select>
</div>
</div>

<div className="row pb-1">
<div className="input-group col-lg-4 bg-danger text-white flexer-new">
<div className="input-group-append form-input">
Expand Down
14 changes: 14 additions & 0 deletions Code/frontend/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { useHistory } from "react-router-dom";
function Header() {
const history = useHistory();

if (!sessionStorage.getItem("login_recipe_recommender")) {
history.push("/login");
}

return (
<div>
<ul className="navbar-ul">
Expand All @@ -15,6 +19,16 @@ function Header() {
Recipe Recommender
</li>

<li
className="navbar-li navbar-li-right"
onClick={() => {
sessionStorage.removeItem("login_recipe_recommender");
history.push("/login");
}}
style={{ cursor: "pointer" }}
>
Logout
</li>
<li
className="navbar-li navbar-li-right"
onClick={() => history.push("/add-recipe")}
Expand Down
13 changes: 11 additions & 2 deletions Code/frontend/src/components/RecipeCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const RecipeCard = ({
imageUrl,
budget,
}) => {
console.log(Cuisine);
const fetchYTId = (url) => {
if (url.length > 0) {
let tmp = url.split("be/")[1];
Expand Down Expand Up @@ -43,7 +42,10 @@ const RecipeCard = ({
title="Embedded youtube"
/>
</StyledYtIFrame>
<StyledBudget>Ingredients Required (Budget: ${budget})</StyledBudget>
<StyledBudget>
<StyledCuisine>Cuisine: {Cuisine}</StyledCuisine>
Ingredients Required (Budget: ${budget})
</StyledBudget>
<StyledIngridients>
{ingredientList(CleanedIngredients).map((ingredient) => (
<StyledIngredient key={ingredient}>
Expand Down Expand Up @@ -152,4 +154,11 @@ const StyledBudget = styled.div`
padding: 4px 8px;
text-align: left;
color: black;
font-weight: 800;
`;

const StyledCuisine = styled.div`
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ https://github.com/Shubh-Nisar/Recipe_Recommender/blob/master/images/recipe-reco
<!-- [![Running Code Coverage](https://github.com/thosaniparth/Recipe_Recommender/actions/workflows/coverage.yml/badge.svg)](https://github.com/thosaniparth/Recipe_Recommender/actions/workflows/coverage.yml) -->

[![Style Checker and Prettify Code](https://github.com/thosaniparth/Recipe_Recommender/actions/workflows/Style_Checker_and_Prettify_Code.yml/badge.svg)](https://github.com/thosaniparth/Recipe_Recommender/actions/workflows/Style_Checker_and_Prettify_Code.yml)
[![Greetings](https://github.com/thosaniparth/Recipe_Recommender/actions/workflows/greetings.yml/badge.svg)](https://github.com/thosaniparth/Recipe_Recommender/actions/workflows/greetings.yml)
[![Greetings](https://github.com/Shubh-Nisar/Recipe_Recommender/actions/workflows/greetings.yml/badge.svg)](https://github.com/Shubh-Nisar/Recipe_Recommender/actions/workflows/greetings.yml)
![Lines of code](https://img.shields.io/badge/Lines%20of%20Code-123.5k-green)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/thosaniparth/Recipe_Recommender)

Expand Down Expand Up @@ -53,7 +53,7 @@ Source documentation can be found at: [Recipe Recommender Docs] https://github.c
![React](https://img.shields.io/badge/react-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB)
![Express.js](https://img.shields.io/badge/express.js-%23404d59.svg?style=for-the-badge&logo=express&logoColor=%2361DAFB)
![NPM](https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white)
![JEST](https://img.shields.io/badge/Jest-C21325?style=for-the-badge&logo=jest&logoColor=white)
![Chai](https://img.shields.io/badge/chai.js-323330?style=for-the-badge&logo=chai&logoColor=red)
![MongoDB](https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge&logo=mongodb&logoColor=white)
![HTML](https://img.shields.io/badge/HTML5-E34F26?style=for-the-badge&logo=html5&logoColor=white)
![CSS](https://img.shields.io/badge/CSS3-1572B6?style=for-the-badge&logo=css3&logoColor=white)
Expand Down

0 comments on commit d73e142

Please sign in to comment.