-
Notifications
You must be signed in to change notification settings - Fork 10
HT 2 #14
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
AlexandrUng
wants to merge
2
commits into
romabelka:master
Choose a base branch
from
AlexandrUng:HT_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
HT 2 #14
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,43 @@ | ||
| import React, { Component } from 'react' | ||
| import { connect } from 'react-redux' | ||
| import { eventsSelector } from '../../ducks/events' | ||
| import { loadEvents } from '../../ducks/events' | ||
|
|
||
| class EventList extends Component { | ||
| static propTypes = {} | ||
|
|
||
| componentDidMount() { | ||
| const { loading, loaded, loadEvents } = this.props | ||
| if (!loaded && !loading) loadEvents() | ||
| } | ||
|
|
||
| render() { | ||
| if (this.props.loading) return <div>Loading...</div> | ||
|
|
||
| return ( | ||
| <div> | ||
| {this.props.events.map((event) => ( | ||
| <li key={event.id}> | ||
| {event.title} | ||
| <p>{event.url}</p> | ||
| <p>{event.where}</p> | ||
| <p>{event.when}</p> | ||
| <p>{event.month}</p> | ||
| <p>{event.submissionDeadline}</p> | ||
| </li> | ||
| ))} | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| (state) => { | ||
| return { | ||
| events: eventsSelector(state), | ||
| loading: state.events.loading, | ||
| loaded: state.events.loaded | ||
| } | ||
| }, | ||
| { loadEvents } | ||
| )(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
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,101 @@ | ||
| import { appName } from '../config' | ||
| import { Record, List } from 'immutable' | ||
| import firebase from 'firebase/app' | ||
| import { takeEvery, put, call } from 'redux-saga/effects' | ||
| import { createSelector } from 'reselect' | ||
|
|
||
| /** | ||
| * Constants | ||
| * */ | ||
| export const moduleName = 'events' | ||
| const prefix = `${appName}/${moduleName}` | ||
|
|
||
| export const LOAD_EVENTS_REQUEST = `${prefix}/LOAD_EVENTS_REQUEST` | ||
| export const LOAD_EVENTS_SUCCESS = `${prefix}/LOAD_EVENTS_SUCCESS` | ||
| export const LOAD_EVENTS_ERROR = `${prefix}/LOAD_EVENTS_ERROR` | ||
|
|
||
| /** | ||
| * Reducer | ||
| * */ | ||
| export const ReducerRecord = Record({ | ||
| entities: new List([]), | ||
| loading: false, | ||
| loaded: false | ||
| }) | ||
| const EventRecord = Record({ | ||
| id: null, | ||
| title: null, | ||
| url: null, | ||
| where: null, | ||
| when: null, | ||
| month: null, | ||
| submissionDeadline: null | ||
| }) | ||
|
|
||
| export default function reducer(state = new ReducerRecord(), action) { | ||
| const { type, payload } = action | ||
|
|
||
| switch (type) { | ||
| case LOAD_EVENTS_REQUEST: | ||
| return state.set('loading', true) | ||
|
|
||
| case LOAD_EVENTS_SUCCESS: | ||
| return state | ||
| .update('entities', (entities) => { | ||
| let newEntities = [] | ||
| for (let id in payload) | ||
| newEntities.push(new EventRecord({ ...payload[id], id })) | ||
| return new List(newEntities) | ||
| }) | ||
| .set('loading', false) | ||
| .set('loaded', true) | ||
|
|
||
| case LOAD_EVENTS_ERROR: | ||
| return state | ||
|
|
||
| default: | ||
| return state | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Selectors | ||
| * */ | ||
|
|
||
| export const stateSelector = (state) => state[moduleName] | ||
| export const eventsSelector = createSelector(stateSelector, (state) => | ||
| state.entities.valueSeq().toArray() | ||
| ) | ||
|
|
||
| /** | ||
| * Action Creators | ||
| * */ | ||
|
|
||
| export function loadEvents() { | ||
| return { | ||
| type: LOAD_EVENTS_REQUEST, | ||
| payload: {} | ||
| } | ||
| } | ||
|
|
||
| export function* loadEventsSaga(action) { | ||
| const databaseEvents = firebase.database().ref('/events/') | ||
|
|
||
| try { | ||
| const snapshot = yield call([databaseEvents, databaseEvents.once], 'value') | ||
|
|
||
| yield put({ | ||
| type: LOAD_EVENTS_SUCCESS, | ||
| payload: snapshot.val() | ||
| }) | ||
| } catch (error) { | ||
| yield put({ | ||
| type: LOAD_EVENTS_ERROR, | ||
| error | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| export function* saga() { | ||
| yield takeEvery(LOAD_EVENTS_REQUEST, loadEventsSaga) | ||
| } | ||
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,21 @@ | ||
| import React, { Component } from 'react' | ||
| import { connect } from 'react-redux' | ||
| import { loadEvents } from '../ducks/events' | ||
| import EventList from '../components/event/event-list' | ||
|
|
||
| class EventsRoute extends Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h1>Events page</h1> | ||
| <button onClick={this.props.loadEvents}>Load events</button> | ||
| <EventList /> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| null, | ||
| { 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.
можно .map, а еще лучше так объектом и хранить