Skip to content

Commit

Permalink
Merge pull request #40 from FoodBuddyApp/RecipeDetail
Browse files Browse the repository at this point in the history
Recipe detail
  • Loading branch information
snayerman authored Apr 30, 2018
2 parents 14a1c36 + ef33110 commit dc95bdd
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 4 deletions.
10 changes: 10 additions & 0 deletions scripts/actions/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export function searchRecipes(url, cb) {
}
}

export function getRecipeDetail(body, cb) {
return (dispatch, prevState) => {
api.getRecipeDetail(body)
.then((response) => {
console.log(response)
dispatch({type: 'GET_RECIPE_DETAIL', recipe: response})
})
.then(() => cb())
}

export function updateDiet(diet) {
return (dispatch, prevState) => {
dispatch({type: 'UPDATE_DIET', diet});
Expand Down
5 changes: 5 additions & 0 deletions scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ export function del(endpoint) {
export function getRecipes(url) {
return get(url)
.then((res) => res.json())
}

export function getRecipeDetail(body) {
return get('recipe/' + body.id)
.then((res) => res.json())
}
28 changes: 25 additions & 3 deletions scripts/components/Main/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from 'react-bootstrap';
import { Route, Switch, Redirect } from 'react-router-dom';
import { LinkContainer } from 'react-router-bootstrap';
import {Search, Recipes} from '../index.js'
import {Search, Recipes, RecipeDetail} from '../index.js'

export default class Main extends Component {
constructor(props) {
Expand All @@ -20,7 +20,7 @@ export default class Main extends Component {
<Navbar>
<Navbar.Header>
<Navbar.Brand>
<a href="#home">Food Buddy</a>
<a href="/">Food Buddy</a>
</Navbar.Brand>
</Navbar.Header>
</Navbar>
Expand All @@ -30,7 +30,29 @@ export default class Main extends Component {
<Route exact path='/'
render={() => <Search {...this.props} />} />
<Route path='/recipes'
render={() => <Recipes {...this.props} />} />
render={() => {
if(this.props.Recipes)
return <Recipes {...this.props} />
else
return <Redirect to='/' />
}}
/>
<Route path='/detail/:id'
render={({match}) => {
console.log(match)
var recipe = this.props.Recipes.find((recipe) =>
recipe.id == match.params.id)
if(recipe) {
return <RecipeDetail
{...recipe}
{...this.props}
/>
}
else {
return <Redirect to='/' />
}
}}
/>
</Switch>
</div>
</div>
Expand Down
43 changes: 43 additions & 0 deletions scripts/components/RecipeDetail/RecipeDetail.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.image {
display: block;
}

.ingredient-list {
text-align: left;
}

.instructions {
text-align: left;
}
.left {
text-align: left;
}
.center {
text-align: center;

}
.text {
float: left;
margin-left: 10px
}

.info {
position: absolute;
bottom: 0;
}

.right {
text-align: right;
}


cell {
border-style: solid;
border-radius: 30px;
border-color: black;
overflow: hidden;
width: 100%;
text-align: left;
margin-bottom: 10px;
}

55 changes: 55 additions & 0 deletions scripts/components/RecipeDetail/RecipeDetail.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, {Component} from 'react';
import './RecipeDetail.css';
import { Image, Button } from 'react-bootstrap';

export default class RecipeDetail extends Component {
constructor(props) {
super(props);

this.state = {};

}
render() {
return (
<div className="centered-div">
<h1>{this.props.title}</h1>
<div className="cell ">
<div className="image">
<Image src={this.props.image} responsive/>
</div>
<div className="text right">
<h2>Recipe info</h2>
<h4 className="left">Servings: {this.props.RecipeDetail.servings}</h4>
{this.props.RecipeDetail.preparationMinutes &&
<h4 className ="left">Prep Time: {this.props.RecipeDetail.preparationMinutes} Minutes</h4>}
{this.props.RecipeDetail.cookingMinutes > 0 ?
(this.props.RecipeDetail.cookingMinutes > 60 ?
<h4>Cooking Time: {this.props.RecipeDetail.cookingMinutes/60} Hours</h4> :
<h4>Cooking Time: {this.props.RecipeDetail.cookingMinutes} Minutes</h4>)
: <h4 className="left">Ready In {this.props.RecipeDetail.readyInMinutes} Minutes</h4>}
</div>
</div>
<div className="cell center">
<h2>Ingredients</h2>
{this.props.missedIngredients.map((user) => {
return <div key={user.id}><h4>{user.originalString}</h4></div>;
})}
{this.props.usedIngredientCount > 0 &&
this.props.usedIngredients.map((user, i) => {
return <div key={i}><h4>{user.originalString}</h4></div>;
})
}
</div>
{this.props.RecipeDetail.analyzedInstructions.length > 0 &&
<div className="cell left">
<h2 className="center">Cooking Instructions</h2>
{this.props.RecipeDetail.analyzedInstructions[0].steps.map((user) => {
return <div key={user.number}><h4><b>Step {user.number}:</b> {user.step}</h4></div>;
})}
</div>
}
</div>
);
}
}

5 changes: 5 additions & 0 deletions scripts/components/RecipeSummary/RecipeSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ export default class Recipes extends Component {
this.state = {};

this.recipeClicked = this.recipeClicked.bind(this)
this.transitionToDetail = this.transitionToDetail.bind(this)
}

recipeClicked() {
this.props.getRecipeDetail({id: this.props.id}, this.transitionToDetail)
}

transitionToDetail() {
this.props.history.push('/detail/' + this.props.id)
}

Expand Down
1 change: 1 addition & 0 deletions scripts/components/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export {default as Search} from './Search/Search';
export {default as Recipes} from './Recipes/Recipes';
export {default as RecipeDetail} from './RecipeDetail/RecipeDetail';
11 changes: 11 additions & 0 deletions scripts/reducers/RecipeDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function RecipeDetail(state = {}, action) {
switch(action.type) {
case 'GET_RECIPE_DETAIL':
return action.recipe;
case 'TEST':
default:
return state;
}
}

export default RecipeDetail;
3 changes: 2 additions & 1 deletion scripts/reducers/rootReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { combineReducers } from 'redux';

import Recipes from './Recipes';
import Options from './Options';
import RecipeDetail from './RecipeDetail';

const rootReducer = combineReducers({Recipes, Options});
const rootReducer = combineReducers({Recipes, Options, RecipeDetail});

export default rootReducer;

0 comments on commit dc95bdd

Please sign in to comment.