From 80a262b0dbd4c40af46310eabe874d14cc15b765 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 10:59:04 +0200 Subject: [PATCH 01/25] init basic app --- .idea/misc.xml | 6 ++++++ src/App.js | 29 ++++++++++++++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..24eb271 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/src/App.js b/src/App.js index 7e261ca..8f39cc6 100644 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,24 @@ import React, { Component } from 'react'; -import logo from './logo.svg'; import './App.css'; +const recipes = ['Waffles', 'Omelets']; + +const Recipe = (props) =>( +
  • { props.recipe }
  • +) + +const Recipes = (props) => ( + +); + class App extends Component { render() { return (
    -
    - logo -

    - Edit src/App.js and save to reload. -

    - - Learn React - -
    +

    Recipes:

    +
    ); } From f166f03de2c80a613050c2fba3923e95149f5b08 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 11:14:59 +0200 Subject: [PATCH 02/25] create state and add form --- src/App.css | 11 +++++++++++ src/App.js | 49 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/App.css b/src/App.css index 92f956e..4018479 100644 --- a/src/App.css +++ b/src/App.css @@ -6,6 +6,17 @@ animation: App-logo-spin infinite 20s linear; height: 40vmin; } +.recipes { + list-style: none; + max-width: 500px; + margin: 20px auto; +} +.recipe { + padding: 20px; + border: 1px solid #beb2b2; + border-radius: 4px; + margin-bottom: 5px; +} .App-header { background-color: #282c34; diff --git a/src/App.js b/src/App.js index 8f39cc6..0ad1075 100644 --- a/src/App.js +++ b/src/App.js @@ -1,27 +1,54 @@ -import React, { Component } from 'react'; +import React, {Component} from 'react'; import './App.css'; -const recipes = ['Waffles', 'Omelets']; -const Recipe = (props) =>( -
  • { props.recipe }
  • +const Recipe = (props) => ( +
  • {props.recipe}
  • ) const Recipes = (props) => ( - + ); class App extends Component { + constructor() { + super(); + + this.state = { + recipes: ['Waffles', 'Omelets'] + } + } + + render() { return ( -
    -

    Recipes:

    - -
    +
    +

    Recipes:

    + +
    + this.title = e} type="text"/> + +
    + + + + +
    ); } + + + onSubmit(e) { + e.preventDefault(); + + const newRecipes = this.state.recipes.concat(this.title.value); + + this.title.value = ''; + + this.setState({recipes: newRecipes}); + } } export default App; From c3ff1cfb2a7ab5c6ba0b060e10fc79dd2064bf5b Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 11:28:49 +0200 Subject: [PATCH 03/25] split to component and pass add recipe --- src/App.js | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/App.js b/src/App.js index 0ad1075..d7aaf43 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,15 @@ import React, {Component} from 'react'; import './App.css'; +/**split the code and passing action to components + * @param props + * @returns {*} + * @constructor + */ const Recipe = (props) => (
  • {props.recipe}
  • -) +); const Recipes = (props) => (
      @@ -12,6 +17,32 @@ const Recipes = (props) => (
    ); + +class AddRecipe extends Component { + constructor() { + super(); + } + + onSubmit(e) { + e.preventDefault(); + + this.props.addRecipe(this.title); + this.title.value = ''; + } + + render() { + return ( +
    + this.title = e} type="text"/> + +
    + + ) + } + +} + + class App extends Component { constructor() { super(); @@ -26,27 +57,15 @@ class App extends Component { return (

    Recipes:

    - -
    - this.title = e} type="text"/> - -
    - + - -
    ); } - onSubmit(e) { - e.preventDefault(); - - const newRecipes = this.state.recipes.concat(this.title.value); - - this.title.value = ''; - + addRecipe = (title) => { + const newRecipes = this.state.recipes.concat(title.value); this.setState({recipes: newRecipes}); } } From 532c531ccec223d83dc653967164f575f55c1db9 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 11:37:37 +0200 Subject: [PATCH 04/25] add ids --- src/App.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index d7aaf43..b7947bd 100644 --- a/src/App.js +++ b/src/App.js @@ -1,19 +1,21 @@ import React, {Component} from 'react'; import './App.css'; -/**split the code and passing action to components +/**Added id to the items * @param props * @returns {*} * @constructor */ +let id = 0; +const getID = () => id += 1; const Recipe = (props) => ( -
  • {props.recipe}
  • +
  • {props.recipe.title}
  • ); const Recipes = (props) => (
      - {props.recipes.map(recipe => )} + {props.recipes.map(recipe => )}
    ); @@ -48,7 +50,11 @@ class App extends Component { super(); this.state = { - recipes: ['Waffles', 'Omelets'] + recipes: [{ + id: getID(), + title: 'Waffles' + },{id: getID(), + title: 'Omelets'}] } } @@ -65,7 +71,10 @@ class App extends Component { addRecipe = (title) => { - const newRecipes = this.state.recipes.concat(title.value); + const newRecipes = this.state.recipes.concat({ + id:getID(), + title: title.value + }); this.setState({recipes: newRecipes}); } } From 7b7a2b9332202ee066a2d76400552f4afce9c516 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 11:47:14 +0200 Subject: [PATCH 05/25] split to file and dirs --- src/App.js | 41 ++++--------------------------------- src/components/AddRecipe.js | 22 ++++++++++++++++++++ src/components/Recipe.js | 5 +++++ src/components/Recipes.js | 8 ++++++++ 4 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 src/components/AddRecipe.js create mode 100644 src/components/Recipe.js create mode 100644 src/components/Recipes.js diff --git a/src/App.js b/src/App.js index b7947bd..f773df8 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,10 @@ import React, {Component} from 'react'; import './App.css'; +import {AddRecipe} from "./components/AddRecipe"; +import {Recipes} from "./components/Recipes"; -/**Added id to the items + +/**Split to files and directories * @param props * @returns {*} * @constructor @@ -9,42 +12,6 @@ import './App.css'; let id = 0; const getID = () => id += 1; -const Recipe = (props) => ( -
  • {props.recipe.title}
  • -); - -const Recipes = (props) => ( -
      - {props.recipes.map(recipe => )} -
    -); - - -class AddRecipe extends Component { - constructor() { - super(); - } - - onSubmit(e) { - e.preventDefault(); - - this.props.addRecipe(this.title); - this.title.value = ''; - } - - render() { - return ( -
    - this.title = e} type="text"/> - -
    - - ) - } - -} - - class App extends Component { constructor() { super(); diff --git a/src/components/AddRecipe.js b/src/components/AddRecipe.js new file mode 100644 index 0000000..cf679a1 --- /dev/null +++ b/src/components/AddRecipe.js @@ -0,0 +1,22 @@ +import React, {Component} from "react"; + +export class AddRecipe extends Component { + + onSubmit(e) { + e.preventDefault(); + + this.props.addRecipe(this.title); + this.title.value = ''; + } + + render() { + return ( +
    + this.title = e} type="text"/> + +
    + + ) + } + +} \ No newline at end of file diff --git a/src/components/Recipe.js b/src/components/Recipe.js new file mode 100644 index 0000000..4d45ed3 --- /dev/null +++ b/src/components/Recipe.js @@ -0,0 +1,5 @@ +import React from 'react'; + +export const Recipe = (props) => ( +
  • {props.recipe.title}
  • +); diff --git a/src/components/Recipes.js b/src/components/Recipes.js new file mode 100644 index 0000000..ecb5ffd --- /dev/null +++ b/src/components/Recipes.js @@ -0,0 +1,8 @@ +import React from 'react'; +import {Recipe} from "./Recipe"; + +export const Recipes = (props) => ( +
      + {props.recipes.map(recipe => )} +
    +); \ No newline at end of file From bd35c1c30f5c3e08e60fc7d9522e66763e88baf6 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 11:49:47 +0200 Subject: [PATCH 06/25] split to file and dirs --- src/App.js | 3 +-- src/services/utils.js | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 src/services/utils.js diff --git a/src/App.js b/src/App.js index f773df8..c7ae7b6 100644 --- a/src/App.js +++ b/src/App.js @@ -2,6 +2,7 @@ import React, {Component} from 'react'; import './App.css'; import {AddRecipe} from "./components/AddRecipe"; import {Recipes} from "./components/Recipes"; +import {getID} from "./services/utils"; /**Split to files and directories @@ -9,8 +10,6 @@ import {Recipes} from "./components/Recipes"; * @returns {*} * @constructor */ -let id = 0; -const getID = () => id += 1; class App extends Component { constructor() { diff --git a/src/services/utils.js b/src/services/utils.js new file mode 100644 index 0000000..ebb46d5 --- /dev/null +++ b/src/services/utils.js @@ -0,0 +1,2 @@ +let id = 0; +export const getID = () => id += 1; From 15c0db7020af093810c39d41e4e124b8aed6de3a Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 11:52:24 +0200 Subject: [PATCH 07/25] split to file and dirs --- src/{ => components/app}/App.css | 0 src/{ => components/app}/App.js | 6 +++--- src/{ => components/app}/App.test.js | 0 src/index.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/{ => components/app}/App.css (100%) rename src/{ => components/app}/App.js (84%) rename src/{ => components/app}/App.test.js (100%) diff --git a/src/App.css b/src/components/app/App.css similarity index 100% rename from src/App.css rename to src/components/app/App.css diff --git a/src/App.js b/src/components/app/App.js similarity index 84% rename from src/App.js rename to src/components/app/App.js index c7ae7b6..8f4b3a4 100644 --- a/src/App.js +++ b/src/components/app/App.js @@ -1,8 +1,8 @@ import React, {Component} from 'react'; import './App.css'; -import {AddRecipe} from "./components/AddRecipe"; -import {Recipes} from "./components/Recipes"; -import {getID} from "./services/utils"; +import {AddRecipe} from "../AddRecipe"; +import {Recipes} from "../Recipes"; +import {getID} from "../../services/utils"; /**Split to files and directories diff --git a/src/App.test.js b/src/components/app/App.test.js similarity index 100% rename from src/App.test.js rename to src/components/app/App.test.js diff --git a/src/index.js b/src/index.js index 0c5e75d..c5daba2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; -import App from './App'; +import App from './components/app/App'; import * as serviceWorker from './serviceWorker'; ReactDOM.render(, document.getElementById('root')); From de5a1dbf28514560f24ef927219af54075bee001 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 12:02:31 +0200 Subject: [PATCH 08/25] propTypes --- package.json | 1 + src/components/AddRecipe.js | 6 +++++- src/components/Recipe.js | 7 ++++++- src/components/Recipes.js | 7 ++++++- src/components/app/App.js | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c410316..62b7464 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "prop-types": "^15.6.2", "react": "^16.6.0", "react-dom": "^16.6.0", "react-scripts": "2.1.1" diff --git a/src/components/AddRecipe.js b/src/components/AddRecipe.js index cf679a1..4d1412f 100644 --- a/src/components/AddRecipe.js +++ b/src/components/AddRecipe.js @@ -1,4 +1,5 @@ import React, {Component} from "react"; +import PropTypes from 'prop-types'; export class AddRecipe extends Component { @@ -18,5 +19,8 @@ export class AddRecipe extends Component { ) } +} -} \ No newline at end of file +AddRecipe.propTypes = { + addRecipe: PropTypes.func.isRequired +}; diff --git a/src/components/Recipe.js b/src/components/Recipe.js index 4d45ed3..03c291e 100644 --- a/src/components/Recipe.js +++ b/src/components/Recipe.js @@ -1,5 +1,10 @@ -import React from 'react'; +import React from 'react'; +import PropTypes from 'prop-types'; export const Recipe = (props) => (
  • {props.recipe.title}
  • ); + +Recipe.propTypes = { + recipe: PropTypes.object.isRequired +}; diff --git a/src/components/Recipes.js b/src/components/Recipes.js index ecb5ffd..2676d32 100644 --- a/src/components/Recipes.js +++ b/src/components/Recipes.js @@ -1,8 +1,13 @@ import React from 'react'; import {Recipe} from "./Recipe"; +import PropTypes from 'prop-types'; export const Recipes = (props) => (
      {props.recipes.map(recipe => )}
    -); \ No newline at end of file +); + +Recipes.propTypes = { + recipes: PropTypes.array.isRequired +}; \ No newline at end of file diff --git a/src/components/app/App.js b/src/components/app/App.js index 8f4b3a4..c01e317 100644 --- a/src/components/app/App.js +++ b/src/components/app/App.js @@ -5,7 +5,7 @@ import {Recipes} from "../Recipes"; import {getID} from "../../services/utils"; -/**Split to files and directories +/**Add prop-types to components need to add prop-types to package.json * @param props * @returns {*} * @constructor From a0107d0d9ce8e97588081f5e4626b0b70d0c2d77 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 12:22:55 +0200 Subject: [PATCH 09/25] propTypes --- package.json | 1 + src/components/Recipe.js | 10 ++++++++-- src/components/app/App.css | 1 + src/components/app/App.js | 18 ++++++++++++------ src/index.css | 5 +++++ 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 62b7464..d01edc4 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "classnames": "^2.2.6", "prop-types": "^15.6.2", "react": "^16.6.0", "react-dom": "^16.6.0", diff --git a/src/components/Recipe.js b/src/components/Recipe.js index 03c291e..edba248 100644 --- a/src/components/Recipe.js +++ b/src/components/Recipe.js @@ -1,8 +1,14 @@ import React from 'react'; import PropTypes from 'prop-types'; +import classNames from 'classnames'; -export const Recipe = (props) => ( -
  • {props.recipe.title}
  • +export const Recipe = ({recipe}) => ( +
  • {recipe.title}
  • ); Recipe.propTypes = { diff --git a/src/components/app/App.css b/src/components/app/App.css index 4018479..4ddc90d 100644 --- a/src/components/app/App.css +++ b/src/components/app/App.css @@ -18,6 +18,7 @@ margin-bottom: 5px; } + .App-header { background-color: #282c34; min-height: 100vh; diff --git a/src/components/app/App.js b/src/components/app/App.js index c01e317..8705da7 100644 --- a/src/components/app/App.js +++ b/src/components/app/App.js @@ -5,7 +5,7 @@ import {Recipes} from "../Recipes"; import {getID} from "../../services/utils"; -/**Add prop-types to components need to add prop-types to package.json +/**Add favirote with classNames to components need to add classNames to package.json * @param props * @returns {*} * @constructor @@ -18,9 +18,13 @@ class App extends Component { this.state = { recipes: [{ id: getID(), - title: 'Waffles' - },{id: getID(), - title: 'Omelets'}] + title: 'Waffles', + favorite: true + }, { + id: getID(), + title: 'Omelets', + favorite: false + }] } } @@ -37,9 +41,11 @@ class App extends Component { addRecipe = (title) => { + const id = getID(); const newRecipes = this.state.recipes.concat({ - id:getID(), - title: title.value + id , + title: title.value, + favorite: false }); this.setState({recipes: newRecipes}); } diff --git a/src/index.css b/src/index.css index cee5f34..6c81b2d 100644 --- a/src/index.css +++ b/src/index.css @@ -12,3 +12,8 @@ code { font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace; } + +.favorite { + font-weight: bold; + background: yellow; +} \ No newline at end of file From 4b68348eb91019b64406e43eb83d4bbecfc37ded Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 6 Nov 2018 14:00:02 +0200 Subject: [PATCH 10/25] propTypes --- src/components/Recipes.js | 13 ------------- src/components/{ => RecipesView}/Recipe.js | 6 ++++-- src/components/RecipesView/Recipes.js | 16 ++++++++++++++++ src/components/app/App.js | 18 ++++++++++++++---- src/components/app/footer/Footer.css | 8 ++++++++ src/components/app/footer/Footer.js | 8 ++++++++ src/components/header/Header.css | 5 +++++ src/components/header/Header.js | 10 ++++++++++ 8 files changed, 65 insertions(+), 19 deletions(-) delete mode 100644 src/components/Recipes.js rename src/components/{ => RecipesView}/Recipe.js (62%) create mode 100644 src/components/RecipesView/Recipes.js create mode 100644 src/components/app/footer/Footer.css create mode 100644 src/components/app/footer/Footer.js create mode 100644 src/components/header/Header.css create mode 100644 src/components/header/Header.js diff --git a/src/components/Recipes.js b/src/components/Recipes.js deleted file mode 100644 index 2676d32..0000000 --- a/src/components/Recipes.js +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import {Recipe} from "./Recipe"; -import PropTypes from 'prop-types'; - -export const Recipes = (props) => ( -
      - {props.recipes.map(recipe => )} -
    -); - -Recipes.propTypes = { - recipes: PropTypes.array.isRequired -}; \ No newline at end of file diff --git a/src/components/Recipe.js b/src/components/RecipesView/Recipe.js similarity index 62% rename from src/components/Recipe.js rename to src/components/RecipesView/Recipe.js index edba248..1a96a08 100644 --- a/src/components/Recipe.js +++ b/src/components/RecipesView/Recipe.js @@ -2,15 +2,17 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -export const Recipe = ({recipe}) => ( +export const Recipe = ({recipe, toggle}) => (
  • toggle(recipe)} >{recipe.title}
  • ); Recipe.propTypes = { - recipe: PropTypes.object.isRequired + recipe: PropTypes.object.isRequired, + toggle: PropTypes.func.isRequired }; diff --git a/src/components/RecipesView/Recipes.js b/src/components/RecipesView/Recipes.js new file mode 100644 index 0000000..53f3591 --- /dev/null +++ b/src/components/RecipesView/Recipes.js @@ -0,0 +1,16 @@ +import React from 'react'; +import {Recipe} from "./Recipe"; +import PropTypes from 'prop-types'; + +export const Recipes = (props) => ( +
      + {props.recipes.map(recipe => )} +
    +); + +Recipes.propTypes = { + recipes: PropTypes.array.isRequired, + toggle: PropTypes.func.isRequired +}; \ No newline at end of file diff --git a/src/components/app/App.js b/src/components/app/App.js index 8705da7..b9a5b71 100644 --- a/src/components/app/App.js +++ b/src/components/app/App.js @@ -1,8 +1,11 @@ import React, {Component} from 'react'; import './App.css'; import {AddRecipe} from "../AddRecipe"; -import {Recipes} from "../Recipes"; +import {Recipes} from "../RecipesView/Recipes"; import {getID} from "../../services/utils"; +import Header from "../header/Header"; +import {Footer} from "./footer/Footer"; + /**Add favirote with classNames to components need to add classNames to package.json @@ -27,14 +30,21 @@ class App extends Component { }] } } + toggleRecipes = (recipe) => { + recipe.favorite = !recipe.favorite; + this.forceUpdate(); + }; + render() { return ( -
    +
    . +

    Recipes:

    - - + + +
    ); } diff --git a/src/components/app/footer/Footer.css b/src/components/app/footer/Footer.css new file mode 100644 index 0000000..6cb0795 --- /dev/null +++ b/src/components/app/footer/Footer.css @@ -0,0 +1,8 @@ +.basic-footer { + background: #807c75; + padding: 10px; + color: white; + position: fixed; + bottom: 0; + width: 100%; +} \ No newline at end of file diff --git a/src/components/app/footer/Footer.js b/src/components/app/footer/Footer.js new file mode 100644 index 0000000..3534e57 --- /dev/null +++ b/src/components/app/footer/Footer.js @@ -0,0 +1,8 @@ +import React from 'react'; +import './Footer.css'; + +export const Footer = () => ( +
    + Our basic React app Recipes +
    +) \ No newline at end of file diff --git a/src/components/header/Header.css b/src/components/header/Header.css new file mode 100644 index 0000000..2a9645a --- /dev/null +++ b/src/components/header/Header.css @@ -0,0 +1,5 @@ +.basic-header { + background: #807c75; + padding: 10px; + color: white; +} \ No newline at end of file diff --git a/src/components/header/Header.js b/src/components/header/Header.js new file mode 100644 index 0000000..18ebf7f --- /dev/null +++ b/src/components/header/Header.js @@ -0,0 +1,10 @@ +import React from 'react' +import './Header.css'; + + const Header = () => ( +
    + Welcome Friends +
    +); + +export default Header \ No newline at end of file From da40693e34ca584807e307e1dc09dd04434b24b4 Mon Sep 17 00:00:00 2001 From: idannaim Date: Tue, 13 Nov 2018 12:04:06 +0200 Subject: [PATCH 11/25] make it one view --- src/components/{ => Recipes}/AddRecipe.js | 0 .../{RecipesView => Recipes}/Recipe.js | 0 .../{RecipesView => Recipes}/Recipes.js | 0 src/components/Recipes/RecipesView.js | 52 +++++++++++++++++++ src/components/app/App.js | 47 ++--------------- 5 files changed, 57 insertions(+), 42 deletions(-) rename src/components/{ => Recipes}/AddRecipe.js (100%) rename src/components/{RecipesView => Recipes}/Recipe.js (100%) rename src/components/{RecipesView => Recipes}/Recipes.js (100%) create mode 100644 src/components/Recipes/RecipesView.js diff --git a/src/components/AddRecipe.js b/src/components/Recipes/AddRecipe.js similarity index 100% rename from src/components/AddRecipe.js rename to src/components/Recipes/AddRecipe.js diff --git a/src/components/RecipesView/Recipe.js b/src/components/Recipes/Recipe.js similarity index 100% rename from src/components/RecipesView/Recipe.js rename to src/components/Recipes/Recipe.js diff --git a/src/components/RecipesView/Recipes.js b/src/components/Recipes/Recipes.js similarity index 100% rename from src/components/RecipesView/Recipes.js rename to src/components/Recipes/Recipes.js diff --git a/src/components/Recipes/RecipesView.js b/src/components/Recipes/RecipesView.js new file mode 100644 index 0000000..fe0d874 --- /dev/null +++ b/src/components/Recipes/RecipesView.js @@ -0,0 +1,52 @@ +import React, {Component} from 'react'; +import {getID} from "../../services/utils"; +import {Recipes} from './Recipes'; +import {AddRecipe} from './AddRecipe'; + + +class RecipesView extends Component { + + constructor() { + super(); + + this.state = { + recipes: [{ + id: getID(), + title: 'Waffles', + favorite: true + }, { + id: getID(), + title: 'Omelets', + favorite: false + }] + } + } + + toggleRecipes = (recipe) => { + recipe.favorite = !recipe.favorite; + this.forceUpdate(); + }; + + + addRecipe = (title) => { + const id = getID(); + const newRecipes = this.state.recipes.concat({ + id, + title: title.value, + favorite: false + }); + this.setState({recipes: newRecipes}); + }; + + render() { + return ( +
    +

    Recipes:

    + + +
    + ) + } +} + +export default RecipesView; \ No newline at end of file diff --git a/src/components/app/App.js b/src/components/app/App.js index b9a5b71..5a942a3 100644 --- a/src/components/app/App.js +++ b/src/components/app/App.js @@ -1,13 +1,10 @@ import React, {Component} from 'react'; import './App.css'; -import {AddRecipe} from "../AddRecipe"; -import {Recipes} from "../RecipesView/Recipes"; -import {getID} from "../../services/utils"; +import RecipesView from "../Recipes/RecipesView"; import Header from "../header/Header"; import {Footer} from "./footer/Footer"; - /**Add favirote with classNames to components need to add classNames to package.json * @param props * @returns {*} @@ -15,50 +12,16 @@ import {Footer} from "./footer/Footer"; */ class App extends Component { - constructor() { - super(); - - this.state = { - recipes: [{ - id: getID(), - title: 'Waffles', - favorite: true - }, { - id: getID(), - title: 'Omelets', - favorite: false - }] - } - } - toggleRecipes = (recipe) => { - recipe.favorite = !recipe.favorite; - this.forceUpdate(); - }; - - - render() { return ( -
    . -
    -

    Recipes:

    - - -