-
Notifications
You must be signed in to change notification settings - Fork 10
Ht2 #13
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
viprogramm
wants to merge
2
commits into
romabelka:master
Choose a base branch
from
viprogramm:ht2
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
Ht2 #13
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,3 @@ | ||
| import React from 'react' | ||
|
|
||
| export default () => <h4>loading...</h4> |
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,7 @@ | ||
| import React from 'react' | ||
|
|
||
| const EventsList = ({ events }) => { | ||
| return <ul>{events.map((event, i) => <li key={i}>{event.title}</li>)}</ul> | ||
| } | ||
|
|
||
| export default EventsList |
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,107 @@ | ||
| import { call, take, put, apply } from 'redux-saga/effects' | ||
| import firebase from 'firebase/app' | ||
| import { | ||
| SIGN_IN_REQUEST, | ||
| SIGN_IN_ERROR, | ||
| SIGN_UP_SUCCESS, | ||
| SIGN_UP_ERROR, | ||
| SIGN_IN_MAX_TRIES_ERROR, | ||
| signInSaga, | ||
| signUpSaga | ||
| } from './auth' | ||
|
|
||
| describe('Saga', () => { | ||
| describe('sign in', () => { | ||
| it('should success', () => { | ||
| const saga = signInSaga() | ||
|
|
||
| expect(saga.next().value).toEqual(take(SIGN_IN_REQUEST)) | ||
|
|
||
| const payload = { email: 'test@test.com', password: 'test password' } | ||
| const auth = firebase.auth() | ||
|
|
||
| expect(saga.next({ payload }).value).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [ | ||
| payload.email, | ||
| payload.password | ||
| ]) | ||
| ) | ||
| }) | ||
|
|
||
| const checkIncorrectSignIn = (saga) => { | ||
| expect(saga.next().value).toEqual(take(SIGN_IN_REQUEST)) | ||
|
|
||
| const payload = { email: 'test@test.com', password: 'test password' } | ||
| const auth = firebase.auth() | ||
|
|
||
| expect(saga.next({ payload }).value).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [ | ||
| payload.email, | ||
| payload.password | ||
| ]) | ||
| ) | ||
| const error = new Error('error') | ||
| expect(saga.throw(error).value).toEqual( | ||
| put({ type: SIGN_IN_ERROR, error }) | ||
| ) | ||
| } | ||
|
|
||
| it('should error', () => { | ||
| const saga = signInSaga() | ||
|
|
||
| for (let i = 0; i < 3; i++) { | ||
| checkIncorrectSignIn(saga) | ||
| } | ||
|
|
||
| expect(saga.next().value).toEqual( | ||
| put({ | ||
| type: SIGN_IN_MAX_TRIES_ERROR | ||
| }) | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe('sign up', () => { | ||
| it('should success', () => { | ||
| const action = { | ||
| payload: { email: 'test@test.conm', password: 'pass12345678' } | ||
| } | ||
| const { payload } = action | ||
| const auth = firebase.auth() | ||
|
|
||
| const saga = signUpSaga(action) | ||
| expect(saga.next().value).toEqual( | ||
| call( | ||
| [auth, auth.createUserWithEmailAndPassword], | ||
| payload.email, | ||
| payload.password | ||
| ) | ||
| ) | ||
| const user = { firstName: 'testName' } | ||
| expect(saga.next(user).value).toEqual( | ||
| put({ type: SIGN_UP_SUCCESS, payload: { user } }) | ||
| ) | ||
| }) | ||
|
|
||
| it('should error', () => { | ||
| const action = { | ||
| payload: { email: 'test@test.conm', password: 'pass12345678' } | ||
| } | ||
| const { payload } = action | ||
| const auth = firebase.auth() | ||
|
|
||
| const saga = signUpSaga(action) | ||
| expect(saga.next().value).toEqual( | ||
| call( | ||
| [auth, auth.createUserWithEmailAndPassword], | ||
| payload.email, | ||
| payload.password | ||
| ) | ||
| ) | ||
| const error = new Error('error msg') | ||
| expect(saga.throw(error).value).toEqual( | ||
| put({ type: SIGN_UP_ERROR, error }) | ||
| ) | ||
| }) | ||
| }) | ||
| }) | ||
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,90 @@ | ||
| import { appName } from '../config' | ||
| import { Record, List } from 'immutable' | ||
| import { createSelector } from 'reselect' | ||
| import firebase from 'firebase/app' | ||
| import { put, takeEvery, call } from 'redux-saga/effects' | ||
|
|
||
| /** | ||
| * Constants | ||
| * */ | ||
| export const moduleName = 'events' | ||
| const prefix = `${appName}/${moduleName}` | ||
| export const EVENTS_REQUEST = `${prefix}/EVENTS_REQUES` | ||
| export const EVENTS_REQUES_SUCCESS = `${prefix}/EVENTS_REQUES_SUCCESS` | ||
|
|
||
| /** | ||
| * Reducer | ||
| * */ | ||
| const ReducerState = Record({ | ||
| entities: new List([]), | ||
| loading: false | ||
| }) | ||
|
|
||
| const EventRecord = Record({ | ||
| title: null, | ||
| url: null, | ||
| where: null, | ||
| when: null, | ||
| month: null, | ||
| submissionDeadline: null | ||
| }) | ||
|
|
||
| export default function reducer(state = new ReducerState(), action) { | ||
| const { type, payload } = action | ||
|
|
||
| switch (type) { | ||
| case EVENTS_REQUEST: | ||
| return state.set('loading', true) | ||
| case EVENTS_REQUES_SUCCESS: | ||
| const { events } = payload | ||
| const newState = state.set('loading', false) | ||
| return Object.keys(events).reduce((acc, key) => { | ||
|
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. Лучше .map, а еще лучше просто об'ектом и хранить |
||
| return acc.update('entities', (entities) => | ||
| entities.push(new EventRecord(events[key])) | ||
| ) | ||
| }, newState) | ||
| default: | ||
| return state | ||
| } | ||
| } | ||
| /** | ||
| * Selectors | ||
| * */ | ||
|
|
||
| export const stateSelector = (state) => state[moduleName] | ||
| export const eventsSelector = createSelector(stateSelector, (state) => | ||
| state.entities.valueSeq().toArray() | ||
| ) | ||
| export const loadingSelector = createSelector( | ||
| stateSelector, | ||
| (state) => state.loading | ||
| ) | ||
|
|
||
| /** | ||
| * Action Creators | ||
| * */ | ||
|
|
||
| export function loadEvents() { | ||
| return { | ||
| type: EVENTS_REQUEST | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sagas | ||
| */ | ||
|
|
||
| export function* loadEvensSaga(action) { | ||
| const ref = firebase.database().ref('events') | ||
| const data = yield call([ref, ref.once], 'value') | ||
| const events = data.val() | ||
|
|
||
| yield put({ | ||
| type: EVENTS_REQUES_SUCCESS, | ||
| payload: { events } | ||
| }) | ||
| } | ||
|
|
||
| export function* saga() { | ||
| yield takeEvery(EVENTS_REQUEST, loadEvensSaga) | ||
| } | ||
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 peopleSaga } from '../ducks/people' | ||
| import { saga as authSaga } from '../ducks/auth' | ||
| import { saga as eventsSaga } from '../ducks/events' | ||
|
|
||
| export default function*() { | ||
| yield all([authSaga(), peopleSaga()]) | ||
| yield all([authSaga(), peopleSaga(), eventsSaga()]) | ||
| } |
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' | ||
| import { connect } from 'react-redux' | ||
|
|
||
| import { loadEvents, loadingSelector, eventsSelector } from '../ducks/events' | ||
| import Loader from '../components/common/loader' | ||
| import EventsList from '../components/events/list' | ||
|
|
||
| class EventsRoute extends Component { | ||
| componentDidMount() { | ||
| this.props.loadEvents() | ||
| } | ||
|
|
||
| render() { | ||
| const { loading, events } = this.props | ||
| return ( | ||
| <div> | ||
| <h1>Events Page</h1> | ||
| {loading && <Loader />} | ||
| <EventsList events={events} /> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| (state) => ({ | ||
| loading: loadingSelector(state), | ||
| events: eventsSelector(state) | ||
| }), | ||
| { loadEvents } | ||
| )(EventsRoute) |
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.
Можно еще редюсер протестить