Skip to content
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
10,161 changes: 10,161 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"git": "^0.1.5",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.1"
Expand All @@ -13,4 +14,4 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
}
79 changes: 67 additions & 12 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import {RecipeCard} from './features/recipe-card.js';
import {Header} from './components/header.js';
import {Input} from './components/input.js';
import {Button} from './components/button.js';
import './App.css';

const APP_ID = 'd1b52cd4'; // your app id here, provided to you when you sign up
const APP_KEY = '04041818465822777105a1e7de33699c'; // your app key here, provided to you when you sign up

// this would be what I would make for the final URL
const BASE_ENDPOINT = `https://api.edamam.com/search?app_id=${APP_ID}&app_key=${APP_KEY}`;
// an example API request with a cake query would be
// `${BASE_ENDPOINT}&q=cake`
// use this to fetch data




class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>

constructor() {
super();
this.state = {
searchTerm: 'cake',
recipeList: [],
error:false,
errorMessage:"",
recipeHeader:"",
};
}
fetchRecipes=()=> {
return fetch(`${BASE_ENDPOINT}&q=${this.state.searchTerm}`)
.then(response => response.json())
.then(
response =>
response.hits.length > 0
? this.setState({ recipeList: [...response.hits], recipeHeader: this.state.searchTerm })
: this.setState({ error: true })
)
.catch(error =>
this.setState({ error: true, errorMessage: error.message})
);
};
componentDidMount() {
this.fetchRecipes();
}

saveSearchTerm = (event) => this.setState({ searchTerm: event.target.value});

render() {
if(!this.state.error){
return (
<div>
<Header>Search some Edamam recipes in this hood</Header>
<Input
onInputChange={this.saveSearchTerm}/>
<Button
onClick={this.fetchRecipes}>Search</Button>
<RecipeCard
searchTerm = {this.state.recipeHeader}
recipes = {this.state.recipeList}/>
</div>
);
}else{
return (
<div>Error message: {this.state.errorMessage}</div>
)
//render error display
}


}
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export const Button = ({children, onClick}) => {
return <button onClick = {onClick}>{children}</button>;
};
8 changes: 8 additions & 0 deletions src/components/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';

export const Header = ({children}) => {
return <h1>{children}</h1>;
};
//default indicates you can name it whatever you want on import
//export default Button;
//export const Button = ButtonComponent rename it (last line and can't be renamed)
5 changes: 5 additions & 0 deletions src/components/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export const Input = ({onInputChange, inputValue}) => {
return <input onChange = {onInputChange} value={inputValue}/>;
};
19 changes: 19 additions & 0 deletions src/features/recipe-card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { Component } from 'react';
import { Recipe } from './recipe';

const capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);

export const RecipeCard = ({ searchTerm, recipes }) => {
return (

<table>
<tr>
<th align='left'>{capitalizeFirstLetter(searchTerm)} Recipe Names</th>
<th>Calories</th>
</tr>
{recipes.map(recipe => <Recipe
label = {recipe.recipe.label}
calories = {recipe.recipe.calories} />)}
</table>
);
};
10 changes: 10 additions & 0 deletions src/features/recipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export const Recipe = ({ label, calories }) => {
return (
<tr>
<td><i> {label}</i></td>
<td> {parseFloat(calories).toFixed(2)}</td>
</tr>
);
};