-
Notifications
You must be signed in to change notification settings - Fork 14
HW2 #16
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
nikola166
wants to merge
1
commit into
romabelka:master
Choose a base branch
from
nikola166:hw2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HW2 #16
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import React, { Component } from 'react' | ||
| import { connect } from 'react-redux' | ||
| import { eventSelector, getListEvent } from '../../ducks/event' | ||
| import Event from './event' | ||
|
|
||
| class EventList extends Component { | ||
| static propTypes = {} | ||
|
|
||
| componentDidMount() { | ||
| this.props.getListEvent() | ||
| } | ||
|
|
||
| render() { | ||
| const { loaded, error, loading } = this.props.event | ||
| if (loading) { | ||
| return ( | ||
| <div> | ||
| <p>Загрузка...</p> | ||
| </div> | ||
| ) | ||
| } else if (error) { | ||
| return ( | ||
| <div> | ||
| <p>Произошла ошибка</p> | ||
| </div> | ||
| ) | ||
| } else if (loaded) { | ||
| return ( | ||
| <div> | ||
| {this.props.eventList.map((event) => ( | ||
| <Event key={event.id} event={event} /> | ||
| ))} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| return null | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| (state) => ({ | ||
| eventList: eventSelector(state), | ||
| event: state.event | ||
| }), | ||
| { getListEvent } | ||
| )(EventList) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React, { Component } from 'react' | ||
|
|
||
| export default class Event extends Component { | ||
| render() { | ||
| const { | ||
| title, | ||
| url, | ||
| where, | ||
| when, | ||
| month, | ||
| submissionDeadline | ||
| } = this.props.event | ||
| return ( | ||
| <div> | ||
| <p>{title}</p> | ||
| <p> | ||
| <a href={url} target="_blank" rel="noopener"> | ||
| {url} | ||
| </a> | ||
| </p> | ||
| <p>{where}</p> | ||
| <p>{when}</p> | ||
| <p>{month}</p> | ||
| <p>{submissionDeadline}</p> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| </div> | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import { put, apply, call, take } from 'redux-saga/effects' | ||
| import firebase from 'firebase/app' | ||
| import { | ||
| signInSaga, | ||
| signUpSaga, | ||
| SIGN_IN_SUCCESS, | ||
| SIGN_IN_REQUEST, | ||
| SIGN_IN_ERROR, | ||
| SIGN_IN_REQUESTS_LIMIT, | ||
| SIGN_UP_REQUEST, | ||
| SIGN_UP_SUCCESS, | ||
| SIGN_UP_ERROR | ||
| } from './auth' | ||
|
|
||
| describe('people auth', () => { | ||
| // Удачный логин | ||
| it('should sign-in', () => { | ||
| const data = { email: 'test@mail.ru', password: '12345678' } | ||
|
|
||
| const sagaProcess = signInSaga({ | ||
| type: SIGN_IN_REQUEST, | ||
| payload: data | ||
| }) | ||
|
|
||
| expect(sagaProcess.next().value).toEqual(take(SIGN_IN_REQUEST)) | ||
|
|
||
| // НЕ понятно зачем передавать {payload: data}. И как это вообще работает | ||
| expect(sagaProcess.next({ payload: data }).value).toEqual( | ||
| call(firebase.auth) | ||
| ) | ||
|
|
||
| const auth = firebase.auth() | ||
|
|
||
| // НЕ понятно зачем передавать auth. И как это вообще работает. | ||
| expect(sagaProcess.next(auth).value).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [data.email, data.password]) | ||
| ) | ||
|
|
||
| const user = apply(auth, auth.signInWithEmailAndPassword, [ | ||
| data.email, | ||
| data.password | ||
| ]) | ||
|
|
||
| expect(sagaProcess.next(user).value).toEqual( | ||
| put({ type: SIGN_IN_SUCCESS, payload: { user } }) | ||
| ) | ||
| }) | ||
|
|
||
| // Limit по авторизации | ||
| it('should sign-in limit', () => { | ||
| const data = { email: 'test@mail.ru', password: '123456' } | ||
|
|
||
| const sagaProcess = signInSaga({ | ||
| type: SIGN_IN_REQUEST, | ||
| payload: data | ||
| }) | ||
|
|
||
| for (let i = 3; i > 0; i--) { | ||
| expect(sagaProcess.next().value).toEqual(take(SIGN_IN_REQUEST)) | ||
|
|
||
| // НЕ понятно зачем передавать {payload: data}. И как это вообще работает | ||
| expect(sagaProcess.next({ payload: data }).value).toEqual( | ||
| call(firebase.auth) | ||
| ) | ||
|
|
||
| const auth = firebase.auth() | ||
|
|
||
| // НЕ понятно зачем передавать auth. И как это вообще работает. | ||
| expect(sagaProcess.next(auth).value).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [ | ||
| data.email, | ||
| data.password | ||
| ]) | ||
| ) | ||
|
|
||
| const user = apply(auth, auth.signInWithEmailAndPassword, [ | ||
| data.email, | ||
| data.password | ||
| ]) | ||
|
|
||
| sagaProcess.next() | ||
| } | ||
|
|
||
| expect(sagaProcess.next().value).toEqual( | ||
| put({ type: SIGN_IN_REQUESTS_LIMIT }) | ||
| ) | ||
| }) | ||
|
|
||
| // Удачное добавление нового пользователя | ||
| it('should sign-up', () => { | ||
| const data = { email: 'test1@mail.ru', password: '12345678' } | ||
|
|
||
| const sagaProcess = signUpSaga({ | ||
| type: SIGN_UP_REQUEST, | ||
| payload: data | ||
| }) | ||
|
|
||
| // НЕ понятно зачем передавать {payload: data}. И как это вообще работает | ||
| expect(sagaProcess.next({ payload: data }).value).toEqual( | ||
| call(firebase.auth) | ||
| ) | ||
|
|
||
| const auth = firebase.auth() | ||
|
|
||
| // НЕ понятно зачем передавать auth. И как это вообще работает. | ||
| expect(sagaProcess.next(auth).value).toEqual( | ||
| apply(auth, auth.createUserWithEmailAndPassword, [ | ||
| data.email, | ||
| data.password | ||
| ]) | ||
| ) | ||
|
|
||
| const user = apply(auth, auth.createUserWithEmailAndPassword, [ | ||
| data.email, | ||
| data.password | ||
| ]) | ||
|
|
||
| expect(sagaProcess.next(user).value).toEqual( | ||
| put({ type: SIGN_UP_SUCCESS, payload: { user } }) | ||
| ) | ||
| }) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ок, но можно бы и reducer потестить |
||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { appName } from '../config' | ||
| import { Record, List } from 'immutable' | ||
| import { createSelector } from 'reselect' | ||
| import { takeEvery, all, put } from 'redux-saga/effects' | ||
| import firebase from 'firebase/app' | ||
|
|
||
| /** | ||
| * Constants | ||
| * */ | ||
| export const moduleName = 'event' | ||
| const prefix = `${appName}/${moduleName}` | ||
| export const GET_LIST_REQUEST = `${prefix}/GET_LIST_REQUEST` | ||
| export const GET_LIST_FAIL = `${prefix}/GET_LIST_FAIL` | ||
| export const GET_LIST_SUCCESS = `${prefix}/GET_LIST_SUCCESS` | ||
|
|
||
| /** | ||
| * Reducer | ||
| * */ | ||
| const ReducerState = Record({ | ||
| entities: new List([]), | ||
| loading: false, | ||
| loaded: false, | ||
| error: null | ||
| }) | ||
|
|
||
| const EventRecord = Record({ | ||
| id: null, | ||
| month: '', | ||
| submissionDeadline: '', | ||
| title: '', | ||
| url: '', | ||
| when: '', | ||
| where: '' | ||
| }) | ||
|
|
||
| export default function reducer(state = new ReducerState(), action) { | ||
| const { type, payload, error } = action | ||
|
|
||
| switch (type) { | ||
| case GET_LIST_REQUEST: | ||
| return state.set('loading', true) | ||
| case GET_LIST_FAIL: | ||
| return state.set('loading', false).set('error', error) | ||
| case GET_LIST_SUCCESS: | ||
| const eventList = Object.keys(payload.list).map((key) => ({ | ||
| id: key, | ||
| ...payload.list[key] | ||
| })) | ||
| return state | ||
| .set( | ||
| 'entities', | ||
| new List(eventList.map((item) => new EventRecord(item))) | ||
| ) | ||
| .set('loading', false) | ||
| .set('loaded', true) | ||
| .set('error', null) | ||
| default: | ||
| return state | ||
| } | ||
| } | ||
| /** | ||
| * Selectors | ||
| * */ | ||
|
|
||
| export const stateSelector = (state) => state[moduleName] | ||
| export const eventSelector = createSelector(stateSelector, (state) => { | ||
| return state.entities.valueSeq().toArray() | ||
| }) | ||
|
|
||
| /** | ||
| * Action Creators | ||
| * */ | ||
|
|
||
| export function getListEvent() { | ||
| return { | ||
| type: GET_LIST_REQUEST, | ||
| payload: {} | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sagas | ||
| * */ | ||
|
|
||
| export function* getEventListSaga() { | ||
| try { | ||
| const eventsRef = yield firebase.database().ref('/events') | ||
|
|
||
| const events = yield eventsRef.once('value') | ||
|
|
||
| yield put({ type: GET_LIST_SUCCESS, payload: { list: events.val() } }) | ||
| } catch (error) { | ||
| yield put({ type: GET_LIST_FAIL, error }) | ||
| } | ||
| } | ||
|
|
||
| export function* saga() { | ||
| yield all([takeEvery(GET_LIST_REQUEST, getEventListSaga)]) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import { all } from 'redux-saga/effects' | ||
| import { saga as authSaga } from '../ducks/auth' | ||
| import { saga as peopleSaga } from '../ducks/people' | ||
| import { saga as eventSaga } from '../ducks/event' | ||
|
|
||
| export default function*() { | ||
| yield all([authSaga(), peopleSaga()]) | ||
| yield all([authSaga(), peopleSaga(), eventSaga()]) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ну эти данные должны как-то внутри генератора оказаться. Почитай как работают генераторы