-
Notifications
You must be signed in to change notification settings - Fork 10
H2 #9
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
ruseev-maxim
wants to merge
11
commits into
romabelka:master
Choose a base branch
from
ruseev-maxim:master
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
H2 #9
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c0110d5
set up firebase
ruseev-maxim 5619885
Merge branch 'master' of https://github.com/romabelka/advreact_25_06 …
ruseev-maxim a097e79
created events duck
ruseev-maxim fa31136
added events reducer
ruseev-maxim 1909743
events saga
ruseev-maxim d7fe1fe
events list component
ruseev-maxim 21580d3
immutable
ruseev-maxim d0b741d
event list view
ruseev-maxim 3590277
auth spec
ruseev-maxim c949d24
auth spec
ruseev-maxim eea14d6
auth spec
ruseev-maxim 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import React, { Component, Fragment } from 'react' | ||
| import { getEvents, eventsSelector, moduleName } from '../../ducks/events' | ||
| import { connect } from 'react-redux' | ||
| import './events.css' | ||
|
|
||
| class EventsList extends Component { | ||
| componentDidMount() { | ||
| this.props.getEvents() | ||
| } | ||
|
|
||
| render() { | ||
| const { events, fetching } = this.props | ||
| { | ||
| if (fetching) { | ||
| return <div>Loading...</div> | ||
| } else { | ||
| return ( | ||
| <div className="events-list"> | ||
| {events.map((event) => ( | ||
| <div className="events-list-item"> | ||
| <div className="events-list-item__title">{event.title}</div> | ||
| <div className="events-list-item__date">{event.when}</div> | ||
| <div className="events-list-item__where">{event.where}</div> | ||
| <div className="events-list-item__url">{event.url}</div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
| return ( | ||
| <div> | ||
| {fetching ? ( | ||
| <div>(</div> | ||
| ) : ( | ||
| <div>{events.map((event) => event.title)}</div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| (state) => ({ | ||
| events: eventsSelector(state), | ||
| fetching: state[moduleName].fetching | ||
| }), | ||
| { getEvents } | ||
| )(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,16 @@ | ||
| .events-list-item { | ||
| box-shadow: 0 1px 3px 0 rgba(0,0,0,.2), 0 1px 1px 0 rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.12); | ||
| padding: 24px 16px; | ||
| font-family: Arial sans-serif; | ||
| margin: 8px; | ||
| max-width: 50%; | ||
| } | ||
|
|
||
| .events-list-item__title { | ||
| font-size: 24px; | ||
| } | ||
|
|
||
| .events-list-item__date { | ||
| font-size: 12px; | ||
| margin-bottom: 12px; | ||
| } |
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,81 @@ | ||
| import { call, put, apply } from 'redux-saga/effects' | ||
| import firebase from 'firebase/app' | ||
| import { | ||
| SIGN_UP_REQUEST, | ||
| SIGN_UP_SUCCESS, | ||
| SIGN_IN_REQUEST, | ||
| SIGN_IN_SUCCESS, | ||
| signUpSaga, | ||
| signInSaga | ||
| } from './auth' | ||
|
|
||
| describe('Auth duck sign up saga', () => { | ||
| it('should sign up with new email and password', () => { | ||
| const auth = firebase.auth() | ||
| const credentials = { | ||
| email: `test${+new Date()}@test.com`, | ||
| password: 'qwerty123' | ||
| } | ||
|
|
||
| const action = { | ||
| type: SIGN_UP_REQUEST, | ||
| payload: credentials | ||
| } | ||
|
|
||
| const saga = signUpSaga(action) | ||
|
|
||
| expect(saga.next().value).toEqual( | ||
| call( | ||
| [auth, auth.createUserWithEmailAndPassword], | ||
| credentials.email, | ||
| credentials.password | ||
| ) | ||
| ) | ||
|
|
||
| const user = { | ||
| email: credentials.email, | ||
| uid: '123' | ||
| } | ||
|
|
||
| expect(saga.next(user).value).toEqual( | ||
| put({ | ||
| type: SIGN_UP_SUCCESS, | ||
| payload: { user } | ||
| }) | ||
| ) | ||
| }) | ||
|
|
||
| it('should sign in', () => { | ||
| const auth = firebase.auth() | ||
|
|
||
| const credentials = { | ||
| email: `test${+new Date()}@test.com`, | ||
| password: 'qwerty123' | ||
| } | ||
|
|
||
| const action = { | ||
| type: SIGN_IN_REQUEST, | ||
| payload: credentials | ||
| } | ||
|
|
||
| const saga = signInSaga(action) | ||
|
|
||
| expect(saga.next().value).toEqual( | ||
| apply(auth, auth.signInWithEmailAndPassword, [ | ||
| credentials.email, | ||
| credentials.password | ||
| ]) | ||
| ) | ||
|
|
||
| const user = { | ||
| email: credentials.email | ||
| } | ||
|
|
||
| expect(saga.next(user).value).toEqual( | ||
| put({ | ||
| type: SIGN_IN_SUCCESS, | ||
| payload: { user } | ||
| }) | ||
| ) | ||
| }) | ||
| }) | ||
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,80 @@ | ||
| import { Record, OrderedMap } from 'immutable' | ||
| import { put, takeLatest, call } from 'redux-saga/effects' | ||
| import { createSelector } from 'reselect' | ||
| import { delay } from 'redux-saga' | ||
| import firebase from 'firebase/app' | ||
|
|
||
| // Constants | ||
| export const moduleName = 'events' | ||
| export const GET_EVENTS_REQUEST = `${moduleName}/GET_EVENTS_REQUEST` | ||
| export const GET_EVENTS_SUCCESS = `${moduleName}/GET_EVENTS_SUCCESS` | ||
| export const GET_EVENTS_ERROR = `${moduleName}/GET_EVENTS_ERROR` | ||
|
|
||
| // Reducer | ||
| const ReducerState = Record({ | ||
| entities: new OrderedMap(), | ||
| fetching: 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 GET_EVENTS_REQUEST: | ||
| return state.set('fetching', true) | ||
| case GET_EVENTS_SUCCESS: | ||
| return state | ||
| .set('fetching', false) | ||
| .set('entities', eventsResponseToState(payload)) | ||
| case GET_EVENTS_ERROR: | ||
| return state.set('fetching', false) | ||
| default: | ||
| return state | ||
| } | ||
| } | ||
|
|
||
| // Selectors | ||
| export const stateSelector = (state) => state[moduleName] | ||
| export const eventsSelector = createSelector(stateSelector, (state) => | ||
| state.entities.valueSeq().toArray() | ||
| ) | ||
|
|
||
| // Action Creators | ||
| export const getEvents = () => ({ | ||
| type: GET_EVENTS_REQUEST | ||
| }) | ||
|
|
||
| // Sagas | ||
| function* getEventsSaga() { | ||
| const ref = firebase.database().ref('/events') | ||
| // делей для видимости лоадера | ||
| yield call(delay, 1000) | ||
|
|
||
| const snapshot = yield call([ref, ref.once], 'value') | ||
|
|
||
| yield put({ | ||
| type: GET_EVENTS_SUCCESS, | ||
| payload: snapshot.val() | ||
| }) | ||
| } | ||
|
|
||
| export function* saga() { | ||
| yield takeLatest(GET_EVENTS_REQUEST, getEventsSaga) | ||
| } | ||
|
|
||
| // utils | ||
| export const eventsResponseToState = (values) => { | ||
| return Object.entries(values).reduce( | ||
| (item, [uid, value]) => item.set(uid, new EventRecord({ uid, ...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
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,15 @@ | ||
| import React, { Component } from 'react' | ||
| import EventsList from '../components/events/events-list' | ||
|
|
||
| class EventsPage extends Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h3>Events list</h3> | ||
| <EventsList /> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default 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.
тест на signIn не работает, не успеваю доделать(