From 29390937b4a1bb7cd46c018ed861147dbc54b65e Mon Sep 17 00:00:00 2001 From: Kirill <908city@gmail.com> Date: Wed, 6 Sep 2017 15:42:37 +0400 Subject: [PATCH 1/3] Add user firebase --- src/config.js | 14 +++++++------- src/ducks/people.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/config.js b/src/config.js index e8d8d78..18292a3 100644 --- a/src/config.js +++ b/src/config.js @@ -1,13 +1,13 @@ import firebase from 'firebase' -export const appName = "advreact-21-08" +export const appName = "advreact-21-081" export const firebaseConfig = { - apiKey: "AIzaSyDjA6CeIHuni5lNm4ML1b-TSxJltsYUO8g", - authDomain: `${appName}.firebaseapp.com`, - databaseURL: `https://${appName}.firebaseio.com`, - projectId: appName, - storageBucket: `${appName}.appspot.com`, - messagingSenderId: "789814589283" + apiKey: "AIzaSyC0hcpDsBhr85usoHIwloBeYbkDHeUcqKo", + authDomain: "advreact-21-081.firebaseapp.com", + databaseURL: "https://advreact-21-081.firebaseio.com", + projectId: "advreact-21-081", + storageBucket: "advreact-21-081.appspot.com", + messagingSenderId: "450237050585" } firebase.initializeApp(firebaseConfig) \ No newline at end of file diff --git a/src/ducks/people.js b/src/ducks/people.js index 6a2a848..27fe890 100644 --- a/src/ducks/people.js +++ b/src/ducks/people.js @@ -3,6 +3,7 @@ import {Record, List} from 'immutable' import {put, call, takeEvery} from 'redux-saga/effects' import {generateId} from './utils' import {reset} from 'redux-form' +import firebase from 'firebase' const ReducerState = Record({ entities: new List([]) @@ -41,8 +42,18 @@ export function addPerson(person) { } export const addPersonSaga = function * (action) { + const id = yield call(generateId) + function saveEventsToFB(person) { + const eventsRef = firebase.database().ref('/people') + eventsRef.push(person); + } + + firebase.database().ref('/people').once('value', data => { + saveEventsToFB(action.payload) + }) + yield put({ type: ADD_PERSON, payload: {...action.payload, id} @@ -51,6 +62,7 @@ export const addPersonSaga = function * (action) { yield put(reset('person')) } + /* export function addPerson(person) { return (dispatch) => { From 56273c2afa851b3706edd17e757a74b69b96db50 Mon Sep 17 00:00:00 2001 From: Kirill <908city@gmail.com> Date: Thu, 7 Sep 2017 13:01:04 +0400 Subject: [PATCH 2/3] add people --- src/components/people/NewPersonForm.js | 2 + src/components/people/PeopleList.js | 61 +++++++++++++++++++++++++ src/ducks/events.js | 2 - src/ducks/people.js | 62 ++++++++++++++++++++------ 4 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 src/components/people/PeopleList.js diff --git a/src/components/people/NewPersonForm.js b/src/components/people/NewPersonForm.js index 2bfed0b..5526636 100644 --- a/src/components/people/NewPersonForm.js +++ b/src/components/people/NewPersonForm.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import {reduxForm, Field} from 'redux-form' import validateEmail from 'email-validator' import ErrorField from '../common/ErrorField' +import PeopleList from './PeopleList' class NewPersonForm extends Component { static propTypes = { @@ -19,6 +20,7 @@ class NewPersonForm extends Component { + ) } diff --git a/src/components/people/PeopleList.js b/src/components/people/PeopleList.js new file mode 100644 index 0000000..f9c19a8 --- /dev/null +++ b/src/components/people/PeopleList.js @@ -0,0 +1,61 @@ +import React, {Component} from 'react' +import {connect} from 'react-redux' +import {moduleName, selectEvent, fetchAll} from '../../ducks/people' +import {Table, Column, InfiniteLoader} from 'react-virtualized' +import 'react-virtualized/styles.css' +import Loader from '../common/Loader' +export class PeopleList extends Component { + static propTypes = {}; + + componentWillMount() { + this.props.fetchAll() + } + + render() { + const {loaded, state, people, loading} = this.props + console.log(people.toArray(), 'state.getHostNode'); + console.log(loading, 'loading'); + + return ( +
+ {loading ? : + + + + +
+ } +
) +} + +rowGetter = ({ index }) =>{ + console.log(this.props.people.toArray()[index].email, 'this.props.people'); + return this.props.people.toArray()[index]; +} + +} + +export default connect(state => ({ + people: state.people, + loading: state[moduleName].loading +}),{fetchAll})(PeopleList) \ No newline at end of file diff --git a/src/ducks/events.js b/src/ducks/events.js index c0ec7a1..d77dbe8 100644 --- a/src/ducks/events.js +++ b/src/ducks/events.js @@ -4,7 +4,6 @@ import {Record, OrderedMap, OrderedSet} from 'immutable' import firebase from 'firebase' import {createSelector} from 'reselect' import {fbDatatoEntities} from './utils' - /** * Constants * */ @@ -36,7 +35,6 @@ export const EventRecord = Record({ when: null, month: null, submissionDeadline: null - }) export default function reducer(state = new ReducerRecord(), action) { diff --git a/src/ducks/people.js b/src/ducks/people.js index 27fe890..78dc104 100644 --- a/src/ducks/people.js +++ b/src/ducks/people.js @@ -1,9 +1,10 @@ import {appName} from '../config' -import {Record, List} from 'immutable' -import {put, call, takeEvery} from 'redux-saga/effects' +import {all, take, call, put, select, takeEvery} from 'redux-saga/effects' import {generateId} from './utils' import {reset} from 'redux-form' import firebase from 'firebase' +import {Record, OrderedMap, OrderedSet,List} from 'immutable' +import {fbDatatoEntities} from './utils' const ReducerState = Record({ entities: new List([]) @@ -16,9 +17,25 @@ const PersonRecord = Record({ email: null }) + +export const ReducerRecord = Record({ + entities: new OrderedMap({}), + selected: new OrderedSet([]), + loading: false, + loaded: false +}) + +export const PeopleRecord = Record({ + email: null, + firstName: null, + lastName: null +}) + export const moduleName = 'people' const prefix = `${appName}/${moduleName}` export const ADD_PERSON_REQUEST = `${prefix}/ADD_PERSON_REQUEST` +export const FETCH_ALL_REQUEST = `${prefix}/FETCH_ALL_REQUEST` +export const FETCH_ALL_SUCCESS = `${prefix}/FETCH_ALL_REQUEST` export const ADD_PERSON = `${prefix}/ADD_PERSON` @@ -27,7 +44,14 @@ export default function reducer(state = new ReducerState(), action) { switch (type) { case ADD_PERSON: - return state.update('entities', entities => entities.push(new PersonRecord(payload))) + return state.update('people', entities => entities.push(new PersonRecord(payload))) + + case FETCH_ALL_SUCCESS: + console.log(payload,'payload'); + return new OrderedMap(payload); + + case FETCH_ALL_REQUEST: + return state.set('loading', true); default: return state @@ -40,6 +64,12 @@ export function addPerson(person) { payload: person } } +export function fetchAll() { + return { + type: FETCH_ALL_REQUEST + } +} + export const addPersonSaga = function * (action) { @@ -63,19 +93,23 @@ export const addPersonSaga = function * (action) { } -/* -export function addPerson(person) { - return (dispatch) => { - dispatch({ - type: ADD_PERSON, - payload: { - person: {id: Date.now(), ...person} - } +export const fetchAllSaga = function * () { + console.log('while start'); + while (true) { + yield console.log('while true') + yield take(FETCH_ALL_REQUEST) + const ref = firebase.database().ref('people') + const data = yield call([ref, ref.once], 'value') + console.log(data.val(), 'data.val()'); + yield put({ + type: FETCH_ALL_SUCCESS, + payload: data.val() }) } } -*/ - export const saga = function * () { - yield takeEvery(ADD_PERSON_REQUEST, addPersonSaga) + yield all([ + fetchAllSaga(), + takeEvery(ADD_PERSON_REQUEST, addPersonSaga), + ]) } From 66ed4d9a459ace731bb7c3f30ec28f0e6dbbc12a Mon Sep 17 00:00:00 2001 From: Kirill <908city@gmail.com> Date: Thu, 7 Sep 2017 15:20:42 +0400 Subject: [PATCH 3/3] tests --- src/components/people/PeopleList.js | 8 ++-- src/components/people/PeopleList.test.js | 17 ++++++++ src/mocks/people.js | 52 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 src/components/people/PeopleList.test.js create mode 100644 src/mocks/people.js diff --git a/src/components/people/PeopleList.js b/src/components/people/PeopleList.js index f9c19a8..f746c52 100644 --- a/src/components/people/PeopleList.js +++ b/src/components/people/PeopleList.js @@ -4,18 +4,16 @@ import {moduleName, selectEvent, fetchAll} from '../../ducks/people' import {Table, Column, InfiniteLoader} from 'react-virtualized' import 'react-virtualized/styles.css' import Loader from '../common/Loader' + export class PeopleList extends Component { static propTypes = {}; - componentWillMount() { + componentDidMount() { this.props.fetchAll() } render() { - const {loaded, state, people, loading} = this.props - console.log(people.toArray(), 'state.getHostNode'); - console.log(loading, 'loading'); - + const {loading, people} = this.props return (
{loading ? : diff --git a/src/components/people/PeopleList.test.js b/src/components/people/PeopleList.test.js new file mode 100644 index 0000000..5ea8ea9 --- /dev/null +++ b/src/components/people/PeopleList.test.js @@ -0,0 +1,17 @@ +import React from 'react' +import {shallow, mount} from 'enzyme' +import events from '../../mocks/conferences' +import {PeopleList} from './PeopleList' +import Loader from '../common/Loader' +import {Table, Column, InfiniteLoader} from 'react-virtualized' +import {Record, OrderedMap, OrderedSet,List} from 'immutable' +import people from '../../mocks/people' + +const testPeople = new OrderedMap({people}) + +it('should render loader', () => { + const container = shallow() + + expect(container.contains()) +}) + diff --git a/src/mocks/people.js b/src/mocks/people.js new file mode 100644 index 0000000..fc7e420 --- /dev/null +++ b/src/mocks/people.js @@ -0,0 +1,52 @@ +export default [ + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + }, + { + "email": "agent@agent.com", + "lastName": "Agent ", + "firstName": "Conf" + } +] \ No newline at end of file