-
Notifications
You must be signed in to change notification settings - Fork 32
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
ДЗ №8 (1) #196
base: necrolyss/homework-8
Are you sure you want to change the base?
ДЗ №8 (1) #196
Conversation
src/components/AuthContext.js
Outdated
} | ||
} | ||
|
||
const AuthConsumerHOC = WrappedComponent => |
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/components/UserPage.js
Outdated
class UserPage extends Component { | ||
|
||
fetchData = () => { | ||
this.props.getLoginRequest(); |
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.
ты должен научить эту компоненту понимать, есть ли имя пользователя и в зависимости от этого отправлять 2 разных экшена getLoginRequest
или getUserInfoRequest
src/ducks/user-actions.js
Outdated
}); | ||
|
||
export { getLoginRequest, getLoginSuccess, getLoginFailure, | ||
getUserInfoRequest, getUserInfoSuccess, getUserInfoFailure }; |
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.
оО тут должно быть 4 экшена, а у тебя целых 6
src/ducks/user-reducers.js
Outdated
getLoginFailure, | ||
getUserInfoRequest, | ||
getUserInfoSuccess, | ||
getUserInfoFailure |
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.
4 экшена
src/ducks/user-reducers.js
Outdated
|
||
const userInfo = handleActions( | ||
{ | ||
[getUserInfoSuccess.toString()]: (_state, action) => action.payload.data |
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.
нужно убрать во всех редьюсерах вот тут вызов toString()
src/sagas/users.js
Outdated
} from "../ducks/user-actions"; | ||
|
||
function* fetchUserWatch(action) { | ||
while (true) { |
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.
Цикл в данном случае не нужен.
Он был нужен конкретно для саги авторизации, там более сложная логика, по которой тебе нужно было научиться понимать разные случаи для пользователя такие, как: пользователь перешел на любую страницу и нужно проверить авторизован ли он или нет
В саге пользователя тебе нужно запускать сагу только при получении конкретных экшенов и делать после этого последовательную работу 1 раз, зачем тут цикл?
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/sagas/users.js
Outdated
while (true) { | ||
try { | ||
const userLookupResult = yield call(getTokenOwner); | ||
let loginSuccessResult = getLoginSuccess(userLookupResult); |
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.
Пожалуйста, называй переменные констистентно:) Очень трудно читать код, когда у тебя сага, относящаяся к пользователю называется searchRequestWatch
- при чем тут поиск вообще?
Приходится тратить гораздо больше времени на чтение кода, когда нет констистентности в именовании
let loginSuccessResult - это можно было бы назвать просто response
src/sagas/users.js
Outdated
} | ||
|
||
function* searchRequestWatch() { | ||
yield takeLatest(getLoginRequest, fetchUserWatch); |
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.
эта сага должна реагировать на 2 экшена, на проверку владельца токена ( getLoginRequest
- его лучше назвать fetchTokenOwnerRequest - тогда сразу понятно, что тут происходит) и второй экшен getUserInfoRequest. В try/catch ты должен в замисимости от того или иного экшена вызывать эффект call (в одном случае в него передавать getTokenOwner, а в другом getUserInformation)
src/sagas/users.js
Outdated
try { | ||
const userLookupResult = yield call(getTokenOwner); | ||
let loginSuccessResult = getLoginSuccess(userLookupResult); | ||
yield put(loginSuccessResult); |
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.
Посмотри внимательно на эту строку, неправильно используешь эффект put
В этот эффект ты должен передать экшен (на строке 20 этого файла ты правильно делаешь)
src/ducks/follower-reducers.js
Outdated
null | ||
); | ||
|
||
export const LOADING_STATE = { |
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/ducks/follower-reducers.js
Outdated
const loadingState = handleActions( | ||
{ | ||
[getFollowersRequest.toString()]: () => LOADING_STATE.loading, | ||
[getFollowersSuccess.toString()]: () => LOADING_STATE.success, |
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.
зачем тут константы?
я уже, кажется, писала про toString()
, по крайней мере говорила про это на групповом созвоне в прошлое воскресенье. так писать не надо
export const isFetched = handleActions(
{
[fetchFollowersRequest]: () => false,
[fetchFollowersSuccess]: () => true,
[fetchFollowersFailure]: () => true
},
false
);
вот так должно быть, просто флаги, не нужно усложнять логику)
Про именование тоже говорила на созвоне, этот редьюсер лучше назвать isFetched
src/ducks/follower-reducers.js
Outdated
export const isFetching = state => { | ||
let currentState = state.login.loadingState; | ||
return currentState === LOADING_STATE.idle | ||
|| currentState === LOADING_STATE.loading; |
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.
используй флаги
export const isFetching = handleActions(
{
[fetchFollowersRequest]: () => true,
[fetchFollowersSuccess]: () => false,
[fetchFollowersFailure]: () => false
},
false
);
У тебя беспорядок со структурой папок и файлов в коде:
|
src/components/Login.js
Outdated
</p> | ||
<input | ||
onChange={this.handleChange} | ||
onKeyPress={(e) => this.handleKeyPress(e)} |
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.
Почему тут (e) => this.handleKetPress(e)? нужно просто onKeyPress={this.handleKeyPress}
src/ducks/followers-reducers.test.js
Outdated
const payload = [ | ||
{ | ||
data: { login: "test1", id: 1 }, | ||
data: { login: "test2", id: 2 } |
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.
Тут второй payload.data затрет первый payload.data, payload будет иметь структуру
[
{
data: {
login: "test2",
id: 2
}
}
]
No description provided.