-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fff951
commit 2e4780f
Showing
5 changed files
with
227 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
async function saveRecipe(recipeData) { | ||
const apiUrl = 'https://recipiebeckend.azurewebsites.net/user/edit-recipe'; // ??????? | ||
const JWTAccessToken = sessionStorage.getItem('accessToken'); | ||
|
||
const formData = new FormData(); | ||
for (const key in recipeData) { | ||
formData.append(key, recipeData[key]); | ||
} | ||
|
||
console.log('formData: ', formData); | ||
|
||
try { | ||
const response = await fetch(apiUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Authorization': JWTAccessToken | ||
}, | ||
body: formData, | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorMessage = await response.text(); | ||
throw new Error(`Failed to save recipe. Status: ${response.status}. Message: ${errorMessage}`); | ||
} | ||
} catch (error) { | ||
console.error('Error saving recipe:', error.message); | ||
throw error; | ||
} | ||
} | ||
|
||
|
||
const saveButton = document.getElementById("save-button"); | ||
saveButton.addEventListener("click", function (event) { | ||
const hours = parseInt(document.getElementById('recipe-prep-hour').value); | ||
const minutes = parseInt(document.getElementById('recipe-prep-minute').value); | ||
const totalMinutes = (hours * 60) + minutes; | ||
|
||
const photoInput = document.getElementById('photo').files[0]; | ||
const recipePhoto = photoInput ? photoInput : null; | ||
|
||
const recipeData = { | ||
title: document.getElementById('recipe-title').value, | ||
ingredients: document.getElementById('recipe-ingredients').value, | ||
description: document.getElementById('recipe-description').value, | ||
cuisine: document.getElementById('recipe-cuisine').value, | ||
meal: document.getElementById('recipe-meal').value, | ||
preparationTime:totalMinutes, | ||
// recipePhoto: document.getElementById('photo').files[0] ? document.getElementById('photo').files[0] : null, | ||
}; | ||
|
||
if (recipePhoto !== null) { | ||
recipeData.recipePhoto = recipePhoto; | ||
} | ||
|
||
event.preventDefault(); | ||
console.log("Save button clicked"); | ||
console.log(recipeData); | ||
|
||
saveRecipe(recipeData); | ||
}); | ||
|
||
|
||
|
||
|
||
function setupBackButton() { | ||
const backButton = document.getElementById('back-arrow-button'); | ||
|
||
backButton.addEventListener('click', () => { | ||
window.history.back(); | ||
// window.history.go(-1); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.form-group { | ||
margin-bottom: 20px; | ||
} | ||
|
||
label { | ||
display: block; | ||
margin-bottom: 5px; | ||
} | ||
|
||
input[type="text"], | ||
textarea { | ||
width: 100%; | ||
padding: 10px; | ||
font-size: 16px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
cursor: pointer; | ||
font-size: 16px; | ||
} | ||
|
||
button:hover { | ||
background-color: #0056b3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="../styles/editUserRecipe.css"> | ||
<title>Edit Recipe</title> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<div id="header-container"> | ||
<button id="back-arrow-button"> | ||
<ion-icon class="back-arrow" name="chevron-back-circle-outline"></ion-icon> | ||
</button> | ||
<h1 id="my-recipe-book-title">Edit Recipe</h1> | ||
</div> | ||
</header> | ||
|
||
<div class="recipe-form-container"> | ||
<h1 class="form-header">Edit Your Recipe</h1> | ||
|
||
<!-- Recipe form --> | ||
<form id="recipe-form" enctype="multipart/form-data"> | ||
<label for="recipe-title">Title:</label> | ||
<input type="text" id="recipe-title" name="title" required> | ||
|
||
<label for="recipe-ingredients">Ingredients:</label> | ||
<textarea id="recipe-ingredients" name="ingredients" required></textarea> | ||
|
||
<label for="recipe-description">Description:</label> | ||
<textarea id="recipe-description" name="description" required></textarea> | ||
|
||
<label for="recipe-cuisine">Cuisine:</label> | ||
<textarea id="recipe-cuisine" name="cuisine"></textarea> | ||
|
||
<label for="recipe-meal">Meal:</label> | ||
<textarea id="recipe-meal" name="meal"></textarea> | ||
|
||
<!-- <label for="recipe-prep-time">Preparation Time:</label> | ||
<input type="text" id="recipe-prep-time" name="prep-time"></input> --> | ||
|
||
<label for="recipe-prep-hour">Preparation Time:</label> | ||
<div class="prep-time-container"> | ||
<select id="recipe-prep-hour" name="prep-hour"> | ||
<option value="0">0 hour</option> | ||
<option value="1">1 hour</option> | ||
<option value="2">2 hours</option> | ||
<option value="3">3 hours</option> | ||
<!-- Add more options as needed --> | ||
</select> | ||
<select id="recipe-prep-minute" name="prep-minute"> | ||
<option value="0">0 minutes</option> | ||
<option value="5">5 minutes</option> | ||
<option value="10">10 minutes</option> | ||
<option value="15">15 minutes</option> | ||
<option value="20">20 minutes</option> | ||
<option value="25">25 minutes</option> | ||
<option value="30">30 minutes</option> | ||
<option value="35">35 minutes</option> | ||
<option value="40">40 minutes</option> | ||
<option value="45">45 minutes</option> | ||
<option value="50">50 minutes</option> | ||
<option value="55">55 minutes</option> | ||
<!-- Add more options as needed --> | ||
</select> | ||
</div> | ||
|
||
<label for="photo">Choose a Photo: <span class="file-name" style="color: black;"></span></label> | ||
<label class="custom-file-input" for="photo"> | ||
Choose File | ||
<input type="file" id="photo" class="photo" name="photo" accept="image/*" onchange="displayFileName(this)"> | ||
</label> | ||
<script> | ||
function displayFileName(input) { | ||
const fileName = input.files[0] ? input.files[0].name : ''; | ||
document.querySelector('.file-name').textContent = fileName; | ||
} | ||
</script> | ||
</form> | ||
|
||
<!-- Back button --> | ||
<div class="button-container"> | ||
<a href="recipe-book.html" id="back-button">Back to Recipe Book</a> | ||
<button type="submit" class="save-button" id="save-button">Save Recipe</button> | ||
</div> | ||
</div> | ||
<script src="../scripts/editUserRecipe.js"></script> | ||
<script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script> | ||
<script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script> | ||
|
||
</body> | ||
|
||
</html> |