Skip to content

Commit c7ef7e2

Browse files
authored
Merge pull request #245 from agiledev-students-spring-2023/Nancy-sprint4
Update share-recipe
2 parents c39d166 + b2b7f79 commit c7ef7e2

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
![Workflow Status](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/actions/workflows/back-end.yml/badge.svg?event=push)
22

33
![Workflow Status](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/actions/workflows/front-end.yml/badge.svg?event=push)
4+
45
## Project Description
56

67
"What's for Dinner" is an open-source web application that suggests recipes based on the ingredients and cooking utensils you have on hand. With our platform, you can search for recipes using specific ingredients, add or remove ingredients to see different recipe suggestions, and save your favorite recipes for future use. Our app also includes advanced search filters such as dietary restrictions, meal type, and cooking time/difficulty to help find the perfect recipe for users at all levels.
@@ -30,7 +31,9 @@ Please refer to the [CONTRIBUTING.md](https://github.com/agiledev-students-sprin
3031
## Instructions to Building and Testing the Project
3132

3233
### Building
34+
3335
**Front-end**
36+
3437
1. first run `cd front-end` to navigate to front-end folder
3538
2. then run `npm install` to install the front-end dependencies
3639
3. create a `.env` file in the front-end directory with the following content:
@@ -56,17 +59,20 @@ CORS_ORIGIN=http://localhost:3001
5659
*Note: For this project, we have provided the following credentials. However, for real projects, please visit "https://www.themealdb.com/" to create an account and replace <MEAL_DB_API_KEY> with your own API key. Similarly, replace <MONGODB_URI> and <SPOONACULAR_API_KEY> with your respective API keys.*
5760

5861
### Running
59-
1. If you are testing either the front-end or back-end, you can run npm start in the corresponding folder.
60-
2. If you are running both the front-end and back-end together, run npm start separately in each folder and view the app on http://localhost:3001.
61-
3. If you are using a Windows PC, please run npm run start-pc instead of npm start for the front-end.
62+
1. If you are testing either the front-end or back-end, you can run `npm start` in the corresponding folder.
63+
2. If you are running both the front-end and back-end together, run `npm start` separately in each folder and view the app on http://localhost:3001.
64+
3. If you are using a Windows PC, please run `npm run start-pc` instead of `npm start` for the front-end.
6265

6366
## Deployed front-end
6467
To view our front-end code live on the web, go to https://monkfish-app-fjlpj.ondigitalocean.app/
6568

69+
6670
## Additional Resources
71+
6772
[README.md](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/blob/master/README.md) - an overview of this project<br>
6873
[LICENSE.md](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/blob/master/LICENSE.md) - the license under which this project is released<br>
6974
[UX-DESIGN.md](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/blob/master/UX-DESIGN.md) - the wireframe diagrams and prototype for this project
7075

71-
### Important Note:
72-
This project is still in development, and we appreciate your patience and feedback as we work to improve the platform. If you have any questions or suggestions, please don't hesitate to reach out to us via the project's GitHub page.
76+
### Important Note
77+
78+
This project is still in development, and we appreciate your patience and feedback as we work to improve the platform. If you have any questions or suggestions, please don't hesitate to reach out to us via the project's GitHub page.

back-end/routes/share-recipes.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@ const express = require("express");
22
const router = express.Router();
33
const Recipe = require('../models/recipes.js');
44

5+
const multer = require('multer');
6+
const storage = multer.diskStorage({
7+
destination: (req, file, cb) => {
8+
cb(null, './uploads/');
9+
},
10+
filename: (req, file, cb) => {
11+
cb(null, Date.now() + file.originalname);
12+
}
13+
});
14+
const upload = multer({ storage: storage });
15+
16+
517
router.post('/', async (req,res) => {
618
try{
719
const recipe = new Recipe({
820
Title: req.body.title,
921
Instructions: req.body.instructions,
1022
Ingredients: req.body.ingredients,
23+
Image: req.file.path
1124
})
1225

1326
await recipe.save();

front-end/src/RecipeList.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect } from "react";
22
import axios from "axios";
3-
import Search from "./Search";
3+
// import Search from "./Search";
44
import { Link } from "react-router-dom"
55
import SortBy from "./SortBy";
66
import SelectIng from "./SelectIng";

front-end/src/ShareRecipe.js

+15-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "./ShareRecipe.css"
44
const ShareRecipe = () => {
55
// Set up state variables to track form input
66
const [title, setTitle] = useState("");
7-
const [description, setDescription] = useState("");
7+
// const [description, setDescription] = useState("");
88
const [ingredients, setIngredients] = useState([]);
99
const [instructions, setInstructions] = useState("");
1010
const [image, setImage] = useState(null);
@@ -15,32 +15,24 @@ const ShareRecipe = () => {
1515
// Create recipe object with form input
1616
const recipe = {
1717
title: title,
18-
description: description,
1918
ingredients: ingredients,
2019
instructions: instructions,
2120
image: image,
2221
};
2322
// Send recipe data
24-
console.log(recipe);
25-
const response = await fetch(`http://localhost:3000/share-recipes`, {
26-
method: 'POST',
27-
body: recipe,
28-
});
2923

30-
// const formData = new FormData();
31-
// formData.append('title', title);
32-
// formData.append('description', description);
33-
// formData.append('instructions', instructions);
34-
// formData.append('image', image);
3524

36-
// ingredients.forEach((ingredient, index) => {
37-
// formData.append(`ingredients[${index}]`, ingredient);
38-
// });
25+
const formData = new FormData();
26+
formData.append('title', title);
27+
formData.append('instructions', instructions);
28+
formData.append('ingredients', JSON.stringify(ingredients));
29+
formData.append('image', image);
3930

40-
// const response = await fetch(`http://localhost:3000/share-recipes`, {
41-
// method: 'POST',
42-
// body: formData,
43-
// });
31+
console.log(recipe);
32+
const response = await fetch('http://localhost:3000/share-recipes', {
33+
method: 'POST',
34+
body: formData
35+
});
4436

4537
if(response.ok){
4638
console.log('Recipe submitted successfully!');
@@ -51,7 +43,7 @@ const ShareRecipe = () => {
5143

5244
// Reset form input
5345
setTitle("");
54-
setDescription("");
46+
// setDescription("");
5547
setIngredients([]);
5648
setInstructions("");
5749
setImage(null);
@@ -86,13 +78,13 @@ const ShareRecipe = () => {
8678
required
8779
/>
8880

89-
<label htmlFor="description">Description:</label>
81+
{/* <label htmlFor="description">Description:</label>
9082
<textarea
9183
id="description"
9284
value={description}
9385
onChange={(e) => setDescription(e.target.value)}
9486
required
95-
></textarea>
87+
></textarea> */}
9688

9789
<label htmlFor="ingredients">Ingredients:</label>
9890
{ingredients.map((ingredient, index) => (
@@ -122,6 +114,7 @@ const ShareRecipe = () => {
122114
id="image"
123115
accept=".jpg,.jpeg,.png"
124116
onChange={handleImageUpload}
117+
required
125118
/>
126119

127120
<button type="submit">Share Recipe</button>

0 commit comments

Comments
 (0)