Skip to content

Commit

Permalink
make route meal take the category main by defualt and from menu
Browse files Browse the repository at this point in the history
relates #39
  • Loading branch information
ranasobeid95 committed Oct 2, 2019
1 parent 923f59d commit 2fc187f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/src/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default () => {
return (
<Router>
<Switch>
<Route exact path="/meals" component={MenuPage} />
<Route path="/meals" component={MenuPage} />
<Route exact path="*" component={Error404} />
</Switch>
</Router>
Expand Down
12 changes: 6 additions & 6 deletions client/src/components/MealPage/Category.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Category = ({ fetchMeals }) => {
<i
className="category_icon white fas fa-turkey"
tabIndex={0}
onClick={() => fetchMeals('Desserts')}
onClick={() => fetchMeals('desserts')}
role="button"
onKeyPress={key => key}
>
Expand All @@ -21,7 +21,7 @@ const Category = ({ fetchMeals }) => {
<i
className="category_icon white fas fa-turkey"
tabIndex={0}
onClick={() => fetchMeals('Breakfast')}
onClick={() => fetchMeals('breakfast')}
role="button"
onKeyPress={key => key}
>
Expand All @@ -32,7 +32,7 @@ const Category = ({ fetchMeals }) => {
<i
className="category_icon white fas fa-turkey"
tabIndex={0}
onClick={() => fetchMeals('Drinks')}
onClick={() => fetchMeals('drinks')}
role="button"
onKeyPress={key => key}
>
Expand All @@ -43,18 +43,18 @@ const Category = ({ fetchMeals }) => {
<i
className="category_icon white fas fa-turkey"
tabIndex={0}
onClick={() => fetchMeals('Sandwishes')}
onClick={() => fetchMeals('sandwishes')}
role="button"
onKeyPress={key => key}
>
Sandwishes
Sandwiches
</i>
</li>
<li>
<i
className="category_icon white fas fa-turkey"
tabIndex={0}
onClick={() => fetchMeals('Main')}
onClick={() => fetchMeals('main')}
role="button"
onKeyPress={key => key}
>
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/MealPage/MealList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import CardMeal from './CardMeal';
import './style.css';

const MealList = ({ data }) => {
console.log(data);

const listItems = data.map(item => {
return (
<li>
Expand Down
19 changes: 12 additions & 7 deletions client/src/components/MealPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import './style.css';
class MenuPage extends React.Component {
state = {
showMenu: true,
category: 'main',
data: [],
};

componentDidMount() {
const { category } = this.state;
this.fetchMeals(category);
this.fetchMeals('main');
}

fetchMeals = category => {
fetchMeals = (cat = 'main') => {
const { history } = this.props;
this.setState({ category });
fetch(`/api/v1/meals?category=${category}`)
history.push(`/meals?category=${cat}`);

fetch(`/api/v1/meals?category=${cat}`)
.then(res => res.json())
.then(result => {
this.setState({
Expand Down Expand Up @@ -54,7 +53,11 @@ class MenuPage extends React.Component {
};

Header = () => {
const { category } = this.state;
const {
location: { search },
} = this.props;
const paramVal = new URLSearchParams(search);
const category = paramVal.get('category');

return (
<header className="header">
Expand Down Expand Up @@ -98,5 +101,7 @@ class MenuPage extends React.Component {
}
MenuPage.propTypes = {
history: PropTypes.objectOf(PropTypes.any).isRequired,
location: PropTypes.objectOf(PropTypes.any).isRequired,
};

export default MenuPage;
4 changes: 3 additions & 1 deletion client/src/components/MealPage/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
border-radius: 8px;
align-items: center;
}

.categoryName{
text-transform: capitalize;
}
.categoryList{
width: 100%;
height: 99vh;
Expand Down

0 comments on commit 2fc187f

Please sign in to comment.