-
Notifications
You must be signed in to change notification settings - Fork 10
Task 2 #10
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
bmind12
wants to merge
3
commits into
romabelka:master
Choose a base branch
from
bmind12:Task-2
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
Task 2 #10
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,18 @@ | ||
| import React, { Component } from 'react' | ||
|
|
||
| export default class EventsItem extends Component { | ||
| render() { | ||
| const { title, url, where, month } = this.props | ||
|
|
||
| return ( | ||
| <li> | ||
| <h3> | ||
| <a href={url}>{title}</a> | ||
| </h3> | ||
| <small> | ||
| {where} in {month} | ||
| </small> | ||
| </li> | ||
| ) | ||
| } | ||
| } |
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,58 @@ | ||
| import React, { Component } from 'react' | ||
| import { connect } from 'react-redux' | ||
| import { | ||
| fetchEvents, | ||
| eventsSelector, | ||
| isLoadingSelector | ||
| } from '../../ducks/events' | ||
| import EventsItem from './events-item' | ||
|
|
||
| class EventsList extends Component { | ||
| componentDidMount() { | ||
| this.props.fetchEvents() | ||
| } | ||
|
|
||
| renderItems = () => { | ||
| return this.props.events.map((conference) => { | ||
| const { | ||
| id, | ||
| title, | ||
| url, | ||
| where, | ||
| when, | ||
| month, | ||
| submissionDeadline | ||
| } = conference | ||
|
|
||
| return ( | ||
| <EventsItem | ||
| key={id} | ||
| title={title} | ||
| url={url} | ||
| where={where} | ||
| when={when} | ||
| month={month} | ||
| submissionDeadline={submissionDeadline} | ||
| /> | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| render() { | ||
| const { events, isLoading } = this.props | ||
|
|
||
| return events && !isLoading ? ( | ||
| <ul>{this.renderItems()}</ul> | ||
| ) : ( | ||
| <div>Loading conferences list</div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| (state) => ({ | ||
| events: eventsSelector(state), | ||
| isLoading: isLoadingSelector(state) | ||
| }), | ||
| { fetchEvents } | ||
| )(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import firebase from 'firebase/app' | ||
| import { apply, call, take, put } from 'redux-saga/effects' | ||
| import reducer, { | ||
| ReducerRecord, | ||
| SIGN_IN_REQUEST, | ||
| SIGN_IN_SUCCESS, | ||
| SIGN_IN_MAX_TRIES_ERROR, | ||
| SIGN_UP_REQUEST, | ||
| SIGN_UP_SUCCESS, | ||
| signInSaga, | ||
| signUpSaga, | ||
| signIn, | ||
| signUp | ||
| } from './auth' | ||
|
|
||
| describe('Saga', () => { | ||
| const payload = { | ||
| email: 'test@test.com', | ||
| password: 'random123' | ||
| } | ||
|
|
||
| it('should sign in', () => { | ||
| const action = { | ||
| type: SIGN_IN_REQUEST, | ||
| payload | ||
| } | ||
|
|
||
| const saga = signInSaga(action) | ||
| const auth = firebase.auth() | ||
|
|
||
| for (let i = 0; i < 3; i++) { | ||
| expect(saga.next().value).toEqual(take(SIGN_IN_REQUEST)) | ||
|
|
||
| expect(saga.next({ payload }).value).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [ | ||
| payload.email, | ||
| payload.password | ||
| ]) | ||
| ) | ||
| } | ||
|
|
||
| expect(saga.next().value).toEqual(put({ type: SIGN_IN_MAX_TRIES_ERROR })) | ||
| }) | ||
|
|
||
| it('should sign up', () => { | ||
| const user = { | ||
| email: 'test@test.com', | ||
| password: 'random123' | ||
| } | ||
|
|
||
| const saga = signUpSaga({ payload }) | ||
| const auth = firebase.auth() | ||
|
|
||
| expect(saga.next().value).toEqual( | ||
| call( | ||
| [auth, auth.createUserWithEmailAndPassword], | ||
| payload.email, | ||
| payload.password | ||
| ) | ||
| ) | ||
|
|
||
| expect(saga.next(user).value).toEqual( | ||
| put({ | ||
| type: SIGN_UP_SUCCESS, | ||
| payload: { user } | ||
| }) | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Action', () => { | ||
| it('should return SIGN_IN_REQUEST action', () => { | ||
| const email = 'test@test.com' | ||
| const password = 'random123' | ||
|
|
||
| expect(signIn(email, password)).toEqual({ | ||
| type: SIGN_IN_REQUEST, | ||
| payload: { email, password } | ||
| }) | ||
| }) | ||
|
|
||
| it('should return SIGN_UP_REQUEST action', () => { | ||
| const email = 'test@test.com' | ||
| const password = 'random123' | ||
|
|
||
| expect(signUp(email, password)).toEqual({ | ||
| type: SIGN_UP_REQUEST, | ||
| payload: { email, password } | ||
| }) | ||
| }) | ||
|
|
||
| it('should return SIGN_UP_REQUEST action', () => { | ||
| const email = 'test@test.com' | ||
| const password = 'random123' | ||
|
|
||
| expect(signUp(email, password)).toEqual({ | ||
| type: SIGN_UP_REQUEST, | ||
| payload: { email, password } | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Reducer', () => { | ||
| it('should return the updated state with signed user', () => { | ||
| const user = { | ||
| email: 'test@test.com', | ||
| password: 'random123' | ||
| } | ||
|
|
||
| const action = { | ||
| type: SIGN_IN_SUCCESS, | ||
| payload: { user } | ||
| } | ||
|
|
||
| const state = new ReducerRecord() | ||
|
|
||
| expect(reducer(undefined, action)).toEqual(state.set('user', { ...user })) | ||
| }) | ||
|
|
||
| it('should return default state state with signed user', () => { | ||
| const action = { type: 'ANY_OTHER_ACTION' } | ||
|
|
||
| const state = new ReducerRecord() | ||
|
|
||
| expect(reducer(undefined, action)).toEqual(state) | ||
| }) | ||
| }) | ||
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,114 @@ | ||
| import { appName } from '../config' | ||
| import { Record, OrderedMap } from 'immutable' | ||
| import firebase from 'firebase/app' | ||
| import { takeLatest, put, call } from 'redux-saga/effects' | ||
| import { createSelector } from 'reselect' | ||
|
|
||
| /** | ||
| * 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_ERROR = `${prefix}/FETCH_EVENTS_ERROR` | ||
|
|
||
| /** | ||
| * Reducer | ||
| * */ | ||
| const ReducerState = Record({ | ||
| data: new OrderedMap(), | ||
| isLoading: false, | ||
| error: null | ||
| }) | ||
|
|
||
| const EventRecord = Record({ | ||
| id: null, | ||
| title: null, | ||
| url: null, | ||
| where: null, | ||
| when: null, | ||
| month: null, | ||
| submissionDeadline: null | ||
| }) | ||
|
|
||
| export default function reducer(state = new ReducerState(), action) { | ||
| const { type, payload, error } = action | ||
|
|
||
| switch (type) { | ||
| case FETCH_EVENTS_REQUEST: { | ||
| return state.set('isLoading', true) | ||
| } | ||
|
|
||
| case FETCH_EVENTS_SUCCESS: { | ||
| return state | ||
| .set('isLoading', false) | ||
| .set('data', createEventsRecords(payload)) | ||
| } | ||
|
|
||
| case FETCH_EVENTS_ERROR: { | ||
| return state.set('isLoading', false).set('error', error) | ||
| } | ||
|
|
||
| default: | ||
| return state | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Selectors | ||
| * */ | ||
| export const stateSelector = (state) => state[moduleName] | ||
| export const eventsSelector = createSelector(stateSelector, (state) => | ||
| state.data.valueSeq().toArray() | ||
| ) | ||
| export const errorSeloctor = createSelector( | ||
| stateSelector, | ||
| (state) => state.error | ||
| ) | ||
| export const isLoadingSelector = createSelector( | ||
| stateSelector, | ||
| (state) => state.isLoading | ||
| ) | ||
|
|
||
| /** | ||
| * Action Creators | ||
| * */ | ||
| export function fetchEvents() { | ||
| return { | ||
| type: FETCH_EVENTS_REQUEST | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sagas | ||
| */ | ||
| export function* fetchEventsSaga() { | ||
| const eventsRef = firebase.database().ref('events') | ||
|
|
||
| try { | ||
| const events = yield call([eventsRef, eventsRef.once], 'value') | ||
|
|
||
| yield put({ | ||
| type: FETCH_EVENTS_SUCCESS, | ||
| payload: events.val() | ||
| }) | ||
| } catch (error) { | ||
| yield put({ | ||
| type: FETCH_EVENTS_ERROR, | ||
| error | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| export function* saga() { | ||
| yield takeLatest(FETCH_EVENTS_REQUEST, fetchEventsSaga) | ||
| } | ||
|
|
||
| function createEventsRecords(events) { | ||
| return Object.entries(events).reduce( | ||
| (eventsMap, [id, value]) => | ||
| eventsMap.set(id, new EventRecord({ id, ...value })), | ||
| new OrderedMap({}) | ||
| ) | ||
| } |
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,16 @@ | ||
| import React, { Component } from 'react' | ||
| import { Route } from 'react-router-dom' | ||
| import EventsList from '../components/events/events-list' | ||
|
|
||
| class Events extends Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h1>Events</h1> | ||
| <Route path="/events/list" component={EventsList} /> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default Events |
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.
лучше это разбить на несколько тест-кейсов