diff --git a/src/App.js b/src/App.js index 0e70188..04f57e5 100644 --- a/src/App.js +++ b/src/App.js @@ -1,49 +1,58 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; - import Header from './components/Header/header'; import Categories from './components/Categories'; import Recipes from './components/Recipes'; -import { initAction } from './actions/initAction'; import './App.css'; -class App extends Component { +class App { static recipeURL = './recipes.json'; - initAction = (data) => { - this.props.initAction(data); + constructor() { + this.data = undefined; + this.renderPromise = undefined; + + this.renderPromise = ( + this + .initialize() + .then( + () => this.render() + ) + ); } - componentDidMount() { - const initAction = this.initAction; + initialize() { - fetch(App.recipeURL) - .then(function (response) { + return fetch(App.recipeURL) + .then((response) => { return response.json(); }) - .then(function (dataJSON) { - initAction(dataJSON); + .then((dataJSON) => { + this.data = dataJSON; }); } render() { return ( + `
-
- - + ${ + Header() + } + ${ + Categories({ + categories: this.data.categories, + }) + } + ${ + Recipes({ + recipes: this.data.recipes, + }) + }
+ ` ); } } -const mapStateToProps = state => ({ - data: state.data, -}); -const mapDispatchToProps = dispatch => ({ - initAction: (data) => dispatch(initAction(data)), -}); - -export default connect(mapStateToProps, mapDispatchToProps)(App); +export default (App); diff --git a/src/actions/initAction.js b/src/actions/initAction.js deleted file mode 100644 index 1db06b2..0000000 --- a/src/actions/initAction.js +++ /dev/null @@ -1,6 +0,0 @@ -export const initAction = (data) => dispatch => { - dispatch({ - type: 'INIT', - payload: data, - }) -} \ No newline at end of file diff --git a/src/components/Categories/categories.js b/src/components/Categories/categories.js index bc3ae3d..a2e30ef 100644 --- a/src/components/Categories/categories.js +++ b/src/components/Categories/categories.js @@ -1,28 +1,23 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; - import CategoryCard from '../CategoryCard'; import './categories.css'; function Categories(props) { return ( + `
- { + ${ props.categories.map((category) => ( - + CategoryCard({ + category, + }) )) }
+ ` ) } - -function mapStateToProps(state) { - return { - categories: state.data.categories || [], - } -} -export default connect(mapStateToProps)(Categories); \ No newline at end of file +export default (Categories); \ No newline at end of file diff --git a/src/components/CategoryCard/categorycard.js b/src/components/CategoryCard/categorycard.js index 9a20cab..afd95bd 100644 --- a/src/components/CategoryCard/categorycard.js +++ b/src/components/CategoryCard/categorycard.js @@ -1,5 +1,3 @@ -import React, { Component } from 'react'; - import './categorycard.css'; function toTitleCase(str) { @@ -12,22 +10,24 @@ function toTitleCase(str) { export default function CategoryCard(props) { return ( + `
- {props.data.name} + ${props.category.name}
- { - toTitleCase(props.data.name) + ${ + toTitleCase(props.category.name) }
- { - `${props.data.restaurants} Resturants` + ${ + `${props.category.restaurants} Resturants` }
+ ` ) -} \ No newline at end of file +} diff --git a/src/components/Header/header.js b/src/components/Header/header.js index 1625cb8..165a71e 100644 --- a/src/components/Header/header.js +++ b/src/components/Header/header.js @@ -1,11 +1,15 @@ -import React, { Component } from 'react'; -// import { connect } from 'react-redux'; - - -import './header.css'; +import headerCSS from './header.css'; export default function Header() { + console.log(headerCSS); + return ( + ` +
What would you like to eat? @@ -13,5 +17,6 @@ export default function Header() {
- ) + ` + ); } \ No newline at end of file diff --git a/src/components/RecipeCard/recipecard.js b/src/components/RecipeCard/recipecard.js index 510e784..45d5742 100644 --- a/src/components/RecipeCard/recipecard.js +++ b/src/components/RecipeCard/recipecard.js @@ -1,5 +1,3 @@ -import React, { Component } from 'react'; - import './recipecard.css'; function toTitleCase(str) { @@ -12,35 +10,37 @@ function toTitleCase(str) { export default function RecipeCard(props) { return ( + `
- {props.data.name} + ${props.recipe.name}
- {props.data.name} + ${props.recipe.name}
- { - toTitleCase(props.data.name) + ${ + toTitleCase(props.recipe.name) }
- { - new Array(props.data.rating).map(_useless => ( + ${ + new Array(props.recipe.rating).map(_useless => ( + `
+ ` )) }
- - { - `$${props.data.price}` + ${ + `$${props.recipe.price}` }
@@ -49,18 +49,21 @@ export default function RecipeCard(props) {
- { - props.data.tags.map(tag => ( + ${ + props.recipe.tags.map(tag => ( + `
- { + ${ toTitleCase(tag) }
+ ` )) }
- ) + ` + ); } \ No newline at end of file diff --git a/src/components/Recipes/recipes.js b/src/components/Recipes/recipes.js index 76be210..a8c210c 100644 --- a/src/components/Recipes/recipes.js +++ b/src/components/Recipes/recipes.js @@ -1,26 +1,21 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; - import RecipeCard from '../RecipeCard'; import './recipes.css'; function Recipes(props) { return ( + `
- { + ${ props.recipes.map((recipe) => ( - + RecipeCard({ + recipe, + }) )) }
- ) + ` + ); } - -function mapStateToProps(state) { - return { - recipes: state.data.recipes || [], - } -} -export default connect(mapStateToProps)(Recipes); \ No newline at end of file +export default (Recipes); \ No newline at end of file diff --git a/src/index.js b/src/index.js index d4a985c..e6f8b88 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,13 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux' -import configureStore from './store'; import './index.css'; import App from './App'; -import * as serviceWorker from './serviceWorker'; -ReactDOM.render( - - - , - document.getElementById('root') -); +window.addEventListener("load", function () { + const app = new App(); -// Disable serviceworker for now -serviceWorker.unregister(); \ No newline at end of file + let elem = document.getElementById('root'); + if (elem !== undefined) { + app.renderPromise.then((appHtml) => { + elem.innerHTML = appHtml; + }) + } +}); \ No newline at end of file diff --git a/src/reducers/initReducer.js b/src/reducers/initReducer.js deleted file mode 100644 index a66727c..0000000 --- a/src/reducers/initReducer.js +++ /dev/null @@ -1,11 +0,0 @@ -export default (state = {}, action) => { - switch (action.type) { - case 'INIT': - return { - ...state, - ...action.payload, - } - default: - return state - } -} \ No newline at end of file diff --git a/src/reducers/rootReducer.js b/src/reducers/rootReducer.js deleted file mode 100644 index bca9107..0000000 --- a/src/reducers/rootReducer.js +++ /dev/null @@ -1,6 +0,0 @@ -import { combineReducers } from 'redux'; -import initReducer from './initReducer'; - -export default combineReducers({ - data: initReducer, -}); \ No newline at end of file