Skip to content

Cookbook #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Cookbook #6

wants to merge 6 commits into from

Conversation

NataliaButenko
Copy link
Collaborator

No description provided.

Copy link
Member

@OlegLustenko OlegLustenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here several functionalities are not implemented:

  1. Sign-in, you have to send the user to the server and validate if such user is in DB
  2. You have to make validation on routes navigation and redirect the user if user not authorized
  3. You can implement adding the recipe, you can just store them offline
  4. Same about the ingredients. It looks like you app not interactive at all

import {HeaderComponent} from "./shared-components/header-component";

class App extends Component {
// constructor() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented code

}
};

changeInputUserName = (event) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be improved this way: https://reactjs.org/docs/forms.html#handling-multiple-inputs

We did something like this in class

import {clearUser} from "../store/actions/user-action/clear-user";

const AuthUserWrapper = (WarappedComponent) => {
class Base extends Component {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty good, it could be improved this way

componentDidMount() {
 if(!this.props.user) {
    thi.props.history.push('/autorization-page')
 }
}

clearUser
};

export default connect(mapStateToProps, mapDispatchToProps)(withRouter(AutorizationComponent));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you router could not work properly due to documentation:
https://reacttraining.com/react-router/web/guides/redux-integration

it could be withRouter(connect()())

It's better to have named exports instead of export default connect. In your scenario it could be hard to debug in react-dev-tool

return recept.id === nextProps.match.params.id
});
if(coincidentalRecept.length === 0) {
nextProps.history.push('/recepts');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.props.history is fine to use. Function would have the same link

return elem.id !== action.payload.recept.id
});
return newState;
}
case TRIGGER_INGRIDIENT_STATE: {
return state.map(recept => {
if(recept.id === action.payload.receptId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to move such logic to action and simplify a reducer to just or so

return action.payload.state

});
}
case REMOVE_INGREDIENT: {
return state.map(recept => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

});
}
case UPDATE_LIST_RECEPTS: {
return state.map(recept => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


return
case INGREDIENTS_TRIGGER: {
let newIngredients = state.map(ingredient => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move logic to action instead of reducer

return(
<ol>
{
recept.ingredients && recept.ingredients.map((ingredient, index) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it worth to move it to method something like renderReducer

You should omit to have a logic inside JSX

return done;
}, []);

if(receptName.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure it could be simplified, something like this

if(receptName.length) {
 return receptName
}

if(ingridientName.length) {
 return ingridientName
}
return []

Seems like it's the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants