mirror of
https://github.com/bendtherules/food-app.git
synced 2026-08-18 13:52:09 +00:00
Refactored - Working without css
This commit is contained in:
+33
-24
@@ -1,49 +1,58 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
import Header from './components/Header/header';
|
import Header from './components/Header/header';
|
||||||
import Categories from './components/Categories';
|
import Categories from './components/Categories';
|
||||||
import Recipes from './components/Recipes';
|
import Recipes from './components/Recipes';
|
||||||
|
|
||||||
import { initAction } from './actions/initAction';
|
|
||||||
|
|
||||||
import './App.css';
|
import './App.css';
|
||||||
|
|
||||||
class App extends Component {
|
class App {
|
||||||
static recipeURL = './recipes.json';
|
static recipeURL = './recipes.json';
|
||||||
|
|
||||||
initAction = (data) => {
|
constructor() {
|
||||||
this.props.initAction(data);
|
this.data = undefined;
|
||||||
|
this.renderPromise = undefined;
|
||||||
|
|
||||||
|
this.renderPromise = (
|
||||||
|
this
|
||||||
|
.initialize()
|
||||||
|
.then(
|
||||||
|
() => this.render()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
initialize() {
|
||||||
const initAction = this.initAction;
|
|
||||||
|
|
||||||
fetch(App.recipeURL)
|
return fetch(App.recipeURL)
|
||||||
.then(function (response) {
|
.then((response) => {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(function (dataJSON) {
|
.then((dataJSON) => {
|
||||||
initAction(dataJSON);
|
this.data = dataJSON;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
`
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Header />
|
${
|
||||||
<Categories />
|
Header()
|
||||||
<Recipes />
|
}
|
||||||
|
${
|
||||||
|
Categories({
|
||||||
|
categories: this.data.categories,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
${
|
||||||
|
Recipes({
|
||||||
|
recipes: this.data.recipes,
|
||||||
|
})
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
export default (App);
|
||||||
data: state.data,
|
|
||||||
});
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
|
||||||
initAction: (data) => dispatch(initAction(data)),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(App);
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
export const initAction = (data) => dispatch => {
|
|
||||||
dispatch({
|
|
||||||
type: 'INIT',
|
|
||||||
payload: data,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,28 +1,23 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
import CategoryCard from '../CategoryCard';
|
import CategoryCard from '../CategoryCard';
|
||||||
|
|
||||||
import './categories.css';
|
import './categories.css';
|
||||||
|
|
||||||
function Categories(props) {
|
function Categories(props) {
|
||||||
return (
|
return (
|
||||||
|
`
|
||||||
<div className="categories-wrapper">
|
<div className="categories-wrapper">
|
||||||
<div className="categories-inner">
|
<div className="categories-inner">
|
||||||
{
|
${
|
||||||
props.categories.map((category) => (
|
props.categories.map((category) => (
|
||||||
<CategoryCard data={category} />
|
CategoryCard({
|
||||||
|
category,
|
||||||
|
})
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default (Categories);
|
||||||
function mapStateToProps(state) {
|
|
||||||
return {
|
|
||||||
categories: state.data.categories || [],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default connect(mapStateToProps)(Categories);
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
|
|
||||||
import './categorycard.css';
|
import './categorycard.css';
|
||||||
|
|
||||||
function toTitleCase(str) {
|
function toTitleCase(str) {
|
||||||
@@ -12,22 +10,24 @@ function toTitleCase(str) {
|
|||||||
|
|
||||||
export default function CategoryCard(props) {
|
export default function CategoryCard(props) {
|
||||||
return (
|
return (
|
||||||
|
`
|
||||||
<div className="category-card" >
|
<div className="category-card" >
|
||||||
<div className="category-card-left">
|
<div className="category-card-left">
|
||||||
<img className="category-card-image" src={props.data.image} alt={props.data.name} />
|
<img className="category-card-image" src=${props.category.image} alt=${props.category.name} />
|
||||||
</div>
|
</div>
|
||||||
<div className="category-card-right">
|
<div className="category-card-right">
|
||||||
<div className="category-card-title">
|
<div className="category-card-title">
|
||||||
{
|
${
|
||||||
toTitleCase(props.data.name)
|
toTitleCase(props.category.name)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div className="category-card-subtitle">
|
<div className="category-card-subtitle">
|
||||||
{
|
${
|
||||||
`${props.data.restaurants} Resturants`
|
`${props.category.restaurants} Resturants`
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import React, { Component } from 'react';
|
import headerCSS from './header.css';
|
||||||
// import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
|
|
||||||
import './header.css';
|
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
|
console.log(headerCSS);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
`
|
||||||
|
<style type="text/css" scoped>
|
||||||
|
${
|
||||||
|
headerCSS
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<div className="header-row">
|
<div className="header-row">
|
||||||
<div className="header-text">
|
<div className="header-text">
|
||||||
What would you like to eat?
|
What would you like to eat?
|
||||||
@@ -13,5 +17,6 @@ export default function Header() {
|
|||||||
<span className="header-icon-notification mdi mdi-bell-outline">
|
<span className="header-icon-notification mdi mdi-bell-outline">
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
|
|
||||||
import './recipecard.css';
|
import './recipecard.css';
|
||||||
|
|
||||||
function toTitleCase(str) {
|
function toTitleCase(str) {
|
||||||
@@ -12,35 +10,37 @@ function toTitleCase(str) {
|
|||||||
|
|
||||||
export default function RecipeCard(props) {
|
export default function RecipeCard(props) {
|
||||||
return (
|
return (
|
||||||
|
`
|
||||||
<div className="recipe-card" >
|
<div className="recipe-card" >
|
||||||
<div className="recipe-card-top">
|
<div className="recipe-card-top">
|
||||||
<img className="recipe-card-image" src={props.data.image} alt={props.data.name} />
|
<img className="recipe-card-image" src=${props.recipe.image} alt=${props.recipe.name} />
|
||||||
</div>
|
</div>
|
||||||
<div className="recipe-card-bottom">
|
<div className="recipe-card-bottom">
|
||||||
<div className="recipe-card-desc">
|
<div className="recipe-card-desc">
|
||||||
<div className="recipe-card-logo-wrapper">
|
<div className="recipe-card-logo-wrapper">
|
||||||
<img className="recipe-card-logo" src={props.data.icon} alt={props.data.name} />
|
<img className="recipe-card-logo" src=${props.recipe.icon} alt=${props.recipe.name} />
|
||||||
</div>
|
</div>
|
||||||
<div className="recipe-card-title-container">
|
<div className="recipe-card-title-container">
|
||||||
<div className="recipe-card-title">
|
<div className="recipe-card-title">
|
||||||
{
|
${
|
||||||
toTitleCase(props.data.name)
|
toTitleCase(props.recipe.name)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div className="recipe-card-rating">
|
<div className="recipe-card-rating">
|
||||||
{
|
${
|
||||||
new Array(props.data.rating).map(_useless => (
|
new Array(props.recipe.rating).map(_useless => (
|
||||||
|
`
|
||||||
<div className="recipe-card-star">
|
<div className="recipe-card-star">
|
||||||
</div>
|
</div>
|
||||||
|
`
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="recipe-card-price">
|
<div className="recipe-card-price">
|
||||||
<div className="recipe-card-price-number">
|
<div className="recipe-card-price-number">
|
||||||
|
${
|
||||||
{
|
`$${props.recipe.price}`
|
||||||
`$${props.data.price}`
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div className="recipe-card-price-suffix">
|
<div className="recipe-card-price-suffix">
|
||||||
@@ -49,18 +49,21 @@ export default function RecipeCard(props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="recipe-card-tags">
|
<div className="recipe-card-tags">
|
||||||
{
|
${
|
||||||
props.data.tags.map(tag => (
|
props.recipe.tags.map(tag => (
|
||||||
|
`
|
||||||
<div className="recipe-card-tag">
|
<div className="recipe-card-tag">
|
||||||
{
|
${
|
||||||
toTitleCase(tag)
|
toTitleCase(tag)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
`
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,21 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
import RecipeCard from '../RecipeCard';
|
import RecipeCard from '../RecipeCard';
|
||||||
|
|
||||||
import './recipes.css';
|
import './recipes.css';
|
||||||
|
|
||||||
function Recipes(props) {
|
function Recipes(props) {
|
||||||
return (
|
return (
|
||||||
|
`
|
||||||
<div className="recipes-wrapper">
|
<div className="recipes-wrapper">
|
||||||
{
|
${
|
||||||
props.recipes.map((recipe) => (
|
props.recipes.map((recipe) => (
|
||||||
<RecipeCard data={recipe} />
|
RecipeCard({
|
||||||
|
recipe,
|
||||||
|
})
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default (Recipes);
|
||||||
function mapStateToProps(state) {
|
|
||||||
return {
|
|
||||||
recipes: state.data.recipes || [],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default connect(mapStateToProps)(Recipes);
|
|
||||||
+9
-13
@@ -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 './index.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import * as serviceWorker from './serviceWorker';
|
|
||||||
|
|
||||||
ReactDOM.render(
|
window.addEventListener("load", function () {
|
||||||
<Provider store={configureStore()}>
|
const app = new App();
|
||||||
<App />
|
|
||||||
</Provider>,
|
|
||||||
document.getElementById('root')
|
|
||||||
);
|
|
||||||
|
|
||||||
// Disable serviceworker for now
|
let elem = document.getElementById('root');
|
||||||
serviceWorker.unregister();
|
if (elem !== undefined) {
|
||||||
|
app.renderPromise.then((appHtml) => {
|
||||||
|
elem.innerHTML = appHtml;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
export default (state = {}, action) => {
|
|
||||||
switch (action.type) {
|
|
||||||
case 'INIT':
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
...action.payload,
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import { combineReducers } from 'redux';
|
|
||||||
import initReducer from './initReducer';
|
|
||||||
|
|
||||||
export default combineReducers({
|
|
||||||
data: initReducer,
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user