-
Notifications
You must be signed in to change notification settings - Fork 14
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
apaulau
wants to merge
3
commits into
romabelka:master
Choose a base branch
from
apaulau: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
3 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,28 @@ | ||
| import React, { Component } from 'react' | ||
| import { connect } from 'react-redux' | ||
| import { eventsSelector } from '../../ducks/events' | ||
|
|
||
| class EventsList extends Component { | ||
| static propTypes = {} | ||
|
|
||
| render() { | ||
| const { events } = this.props | ||
| return ( | ||
| <ol> | ||
| {Object.keys(events).map((key) => ( | ||
| <li key={key}> | ||
| {events[key].title} | ||
| <br /> | ||
| <b>Where:</b> {events[key].where} | ||
| <br /> | ||
| <b>When:</b> {events[key].when} | ||
| </li> | ||
| ))} | ||
| </ol> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect((state) => ({ | ||
| events: eventsSelector(state) | ||
| }))(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
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,126 @@ | ||
| import { | ||
| signUpSaga, | ||
| SIGN_UP_REQUEST, | ||
| SIGN_UP_SUCCESS, | ||
| SIGN_UP_ERROR, | ||
| signInSaga, | ||
| SIGN_IN_REQUEST, | ||
| SIGN_IN_REQUESTS_LIMIT, | ||
| SIGN_IN_SUCCESS, | ||
| SIGN_IN_ERROR | ||
| } from './auth' | ||
| import { call, put, take, apply } from 'redux-saga/effects' | ||
| import firebase from 'firebase/app' | ||
|
|
||
| describe('auth duck', () => { | ||
| it('should sign up', () => { | ||
| const user = { | ||
| email: 'test@test.com', | ||
| password: 'something_secret' | ||
| } | ||
|
|
||
| const saga = signUpSaga({ | ||
| type: SIGN_UP_REQUEST, | ||
| payload: user | ||
| }) | ||
|
|
||
| const auth = firebase.auth() | ||
|
|
||
| expect(saga.next().value).toEqual( | ||
| call( | ||
| [auth, auth.createUserWithEmailAndPassword], | ||
| user.email, | ||
| user.password | ||
| ) | ||
| ) | ||
|
|
||
| expect(saga.next(user).value).toEqual( | ||
| put({ type: SIGN_UP_SUCCESS, payload: { user } }) | ||
| ) | ||
| }) | ||
|
|
||
| it('should handle failed sign up', () => { | ||
| const user = { | ||
| email: '', | ||
| password: '' | ||
| } | ||
|
|
||
| const saga = signUpSaga({ | ||
| type: SIGN_UP_REQUEST, | ||
| payload: user | ||
| }) | ||
|
|
||
| const auth = firebase.auth() | ||
|
|
||
| expect(saga.next().value).toEqual( | ||
| call( | ||
| [auth, auth.createUserWithEmailAndPassword], | ||
| user.email, | ||
| user.password | ||
| ) | ||
| ) | ||
|
|
||
| expect(saga.throw('error').value).toEqual( | ||
| put({ type: SIGN_UP_ERROR, error: 'error' }) | ||
| ) | ||
| }) | ||
|
|
||
| it('should sign in', () => { | ||
| const user = { | ||
| email: 'test@test.com', | ||
| password: 'something_secret' | ||
| } | ||
|
|
||
| const saga = signInSaga() | ||
|
|
||
| expect(saga.next().value).toEqual(take(SIGN_IN_REQUEST)) | ||
|
|
||
| const auth = firebase.auth() | ||
|
|
||
| expect( | ||
| saga.next({ | ||
| type: SIGN_IN_REQUEST, | ||
| payload: user | ||
| }).value | ||
| ).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [user.email, user.password]) | ||
| ) | ||
|
|
||
| expect(saga.next(user).value).toEqual( | ||
| put({ type: SIGN_IN_SUCCESS, payload: { user } }) | ||
| ) | ||
| }) | ||
|
|
||
| it('should handle failed sign in', () => { | ||
| const user = { | ||
| email: '', | ||
| password: '' | ||
| } | ||
|
|
||
| const saga = signInSaga() | ||
|
|
||
| for (let i = 0; i < 3; i++) { | ||
| expect(saga.next().value).toEqual(take(SIGN_IN_REQUEST)) | ||
|
|
||
| const auth = firebase.auth() | ||
|
|
||
| expect( | ||
| saga.next({ | ||
| type: SIGN_IN_REQUEST, | ||
| payload: user | ||
| }).value | ||
| ).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [ | ||
| user.email, | ||
| user.password | ||
| ]) | ||
| ) | ||
|
|
||
| expect(saga.throw('error').value).toEqual( | ||
| put({ type: SIGN_IN_ERROR, error: 'error' }) | ||
| ) | ||
| } | ||
|
|
||
| expect(saga.next().value).toEqual(put({ type: SIGN_IN_REQUESTS_LIMIT })) | ||
| }) | ||
|
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,94 @@ | ||
| import { appName } from '../config' | ||
| import { Record, Map } from 'immutable' | ||
| import { createSelector } from 'reselect' | ||
| import { takeEvery, all, put, call } from 'redux-saga/effects' | ||
| import firebase from 'firebase/app' | ||
|
|
||
| /** | ||
| * Constants | ||
| * */ | ||
| export const moduleName = 'events' | ||
| const prefix = `${appName}/${moduleName}` | ||
| export const FETCH_EVENTS_REQUEST = `${prefix}/FETCH_EVENTS_REQUEST` | ||
| export const FETCH_EVENTS_SUCCESS = `${prefix}/FETCH_EVENTS_SUCCESS` | ||
| export const FETCH_EVENTS_FAIL = `${prefix}/FETCH_EVENTS_FAIL` | ||
|
|
||
| /** | ||
| * Reducer | ||
| * */ | ||
| const ReducerState = Record({ | ||
| loading: false, | ||
| loaded: false, | ||
| entities: new Map({}) | ||
| }) | ||
|
|
||
| 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 FETCH_EVENTS_REQUEST: | ||
| return state.set('loading', true) | ||
|
|
||
| case FETCH_EVENTS_SUCCESS: | ||
| return state | ||
| .set('loading', false) | ||
| .set('loaded', true) | ||
| .update('entities', (entities) => | ||
| Object.entries(payload).reduce( | ||
| (map, [key, value]) => map.set(key, new EventRecord(value)), | ||
| new Map({}) | ||
|
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. возможно лучше OrederedMap |
||
| ) | ||
| ) | ||
|
|
||
| case FETCH_EVENTS_FAIL: | ||
| return state.set('loading', false).set('loaded', false) | ||
|
|
||
| default: | ||
| return state | ||
| } | ||
| } | ||
| /** | ||
| * Selectors | ||
| * */ | ||
|
|
||
| export const stateSelector = (state) => state[moduleName] | ||
| export const eventsSelector = createSelector(stateSelector, (state) => | ||
| state.entities.toObject() | ||
| ) | ||
|
|
||
| /** | ||
| * Action Creators | ||
| * */ | ||
|
|
||
| export function fetchEvents() { | ||
| return { type: FETCH_EVENTS_REQUEST } | ||
| } | ||
|
|
||
| /** | ||
| * Sagas | ||
| * */ | ||
|
|
||
| export function* fetchEventsSaga() { | ||
| const database = firebase.database().ref('/events') | ||
|
|
||
| try { | ||
| const data = yield call([database, database.once], 'value') | ||
|
|
||
| yield put({ type: FETCH_EVENTS_SUCCESS, payload: data.val() }) | ||
| } catch (error) { | ||
| yield put({ type: FETCH_EVENTS_FAIL, payload: error }) | ||
| } | ||
| } | ||
|
|
||
| export function* saga() { | ||
| yield all([takeEvery(FETCH_EVENTS_REQUEST, fetchEventsSaga)]) | ||
| } | ||
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 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
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,35 @@ | ||
| import React, { Component } from 'react' | ||
| import { connect } from 'react-redux' | ||
| import EventsList from '../components/events/events-list' | ||
| import { fetchEvents, stateSelector } from '../ducks/events' | ||
|
|
||
| class EventsPage extends Component { | ||
| static propTypes = {} | ||
|
|
||
| componentWillMount = () => { | ||
| if (this.props.loading || this.props.loaded) return | ||
|
|
||
| this.props.fetchEvents() | ||
| } | ||
|
|
||
| render() { | ||
| const { loading, loaded } = this.props | ||
|
|
||
| const body = loading && !loaded ? <b>Loading...</b> : <EventsList /> | ||
|
|
||
| return ( | ||
| <div> | ||
| <h2>Events</h2> | ||
| {body} | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| (state) => { | ||
| const { loading, loaded } = stateSelector(state) | ||
| return { loading, loaded } | ||
| }, | ||
| { fetchEvents } | ||
| )(EventsPage) |
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.
Я б для Event сразу отдельный компонент заводил