-
Notifications
You must be signed in to change notification settings - Fork 30
(User) add logout button and authorization check #2
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
base: chp13-optimize-re-renders
Are you sure you want to change the base?
Conversation
src/actions/UserActions.js
Outdated
type: LOGIN_STATUS_REQUEST, | ||
}) | ||
|
||
// eslint-disable-next-line no-undef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я добавил в .eslintrc globals VK, теперь можно не выключать строку
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
очень странно, не работает у меня "globals": { "VK": true }, хотя правила работают и плагин Eslint для VSCode тоже нормально срабатывает
src/actions/UserActions.js
Outdated
dispatch({ | ||
type: LOGOUT_REQUEST, | ||
}) | ||
// eslint-disable-next-line no-undef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
аналогично (нужно удалить)
const { name, handleLogout, handleLogin, isFetching } = this.props | ||
const authorized = Boolean(name) | ||
const btnName = authorized ? 'Выйти' : 'Войти' | ||
const onClick = authorized ? handleLogout : handleLogin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/reducers/user.js
Outdated
return { ...state, isFetching: false, error: action.payload.message } | ||
|
||
case t.LOGIN_STATUS_REQUEST: | ||
return { ...state, isFetching: true, error: '' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно объединить одинаковые case, например:
case t.LOGIN_REQUEST:
case t.LOGIN_STATUS_REQUEST:
case t.LOGOUT_REQUEST:
return { ...state, isFetching: true, error: '' }
p.s. так же посмотри остальные
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point.
у redux-actions вроде нельзя так сделать, не помнишь ?
src/reducers/user.js
Outdated
return { ...state, isFetching: true, error: '' } | ||
|
||
case t.LOGIN_STATUS_SUCCESS: | ||
return { ...state, isFetching: false, error: '', name: action.payload } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я думаю, что если мы на *_REQUEST обнуляем ошибку, то на *_SUCCESS ее уже быть не может и поэтому можно удалить лишний код: error: ''
…rse-ru-v2 into art/login-btn-fixed
No description provided.