diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file 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/package.json b/package.json index c410316..e3fcde8 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,14 @@ "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", - "react-scripts": "2.1.1" + "react-redux": "^5.1.1", + "react-router-dom": "^4.3.1", + "react-scripts": "2.1.1", + "redux": "^4.0.1" }, "scripts": { "start": "react-scripts start", diff --git a/src/App.js b/src/App.js deleted file mode 100644 index 7e261ca..0000000 --- a/src/App.js +++ /dev/null @@ -1,28 +0,0 @@ -import React, { Component } from 'react'; -import logo from './logo.svg'; -import './App.css'; - -class App extends Component { - render() { - return ( -
-
- logo -

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

- - Learn React - -
-
- ); - } -} - -export default App; diff --git a/src/actions/recipes.js b/src/actions/recipes.js new file mode 100644 index 0000000..13e8c96 --- /dev/null +++ b/src/actions/recipes.js @@ -0,0 +1,24 @@ +import * as consts from '../constants/actions-types'; + +export const addRecipe = (recipe) => ({ + type: consts.ADD_RECIPE, + payload: { + title: recipe.title, + description: recipe.description, + id: recipe.id + } +}); + +export const toggleRecipe = (recipe) => ({ + type: consts.TOGGLE_RECIPE, + payload: recipe.id +}); + +export const fetchRecipes = () => ({ + type: consts.API, + payload: { + url: 'recipes.json', + success: consts.SET_RECIPES + } + +}) diff --git a/src/actions/user.js b/src/actions/user.js new file mode 100644 index 0000000..9868770 --- /dev/null +++ b/src/actions/user.js @@ -0,0 +1,6 @@ +import {SET_USER} from '../constants/actions-types' + +export const changeUser = (name) => ({ + type: SET_USER, + payload: {name} +}); \ No newline at end of file diff --git a/src/components/Recipes/AddRecipe.js b/src/components/Recipes/AddRecipe.js new file mode 100644 index 0000000..c716f0e --- /dev/null +++ b/src/components/Recipes/AddRecipe.js @@ -0,0 +1,41 @@ +import React, {Component} from "react"; +import PropTypes from 'prop-types'; +import {connect} from 'react-redux'; +import {addRecipe} from '../../actions/recipes'; +import {withRouter} from 'react-router-dom'; +import {getID} from "../../services/utils"; + +class AddRecipe extends Component { + + onSubmit(e) { + e.preventDefault(); + + const id = getID(); + this.props.addRecipe({id, title: this.title.value, description: this.description.value}); + this.title.value = ''; + this.description.value = ''; + } + + render() { + return ( +
+
+ this.title = e} type="text"/> +
+
+ +