Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions admin/src/components/people/people-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react'
import { connect } from 'react-redux'
import { peopleSelector, fetchAllPeople } from '../../ducks/people'
import { List } from 'react-virtualized'
import { TransitionMotion, spring } from 'react-motion'
import PersonCard from './person-card'

import 'react-virtualized/styles.css'
Expand All @@ -13,24 +14,43 @@ class PeopleList extends Component {

render() {
return (
<List
rowRenderer={this.rowRenderer}
rowCount={this.props.people.length}
rowHeight={150}
height={400}
width={400}
/>
<TransitionMotion styles={this.getStyles()} willEnter={this.willEnter}>
{(interpolated) => (
<List
rowRenderer={this.rowRenderer(interpolated)}
rowCount={interpolated.length}
rowHeight={150}
height={400}
width={400}
/>
)}
</TransitionMotion>
)
}

rowRenderer = ({ style, index, key }) => {
const person = this.props.people[index]
rowRenderer = (interpolated) => ({ style, index, key }) => {
const item = interpolated[index]

return (
<div style={style} key={key}>
<PersonCard person={person} />
<div style={{ ...style, ...item.style }} key={key}>
<PersonCard person={item.data} />
</div>
)
}

willEnter = () => ({
opacity: 0
})

getStyles = () => {
return this.props.people.map((person) => ({
key: person.uid,
style: {
opacity: spring(1, { stiffness: 20, dumping: 30 })
},
data: person
}))
}
}

export default connect(
Expand Down
41 changes: 31 additions & 10 deletions admin/src/ducks/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { appName } from '../config'
import { Record } from 'immutable'
import firebase from 'firebase/app'
import { createSelector } from 'reselect'
import { all, call, apply, put, takeEvery, take } from 'redux-saga/effects'
import {
all,
call,
apply,
put,
takeEvery,
take,
spawn
} from 'redux-saga/effects'
import { eventChannel } from 'redux-saga'

/**
* Constants
Expand Down Expand Up @@ -114,15 +123,27 @@ export function* signInSaga() {
yield put({ type: SIGN_IN_REQUESTS_LIMIT })
}

export function* saga() {
yield all([takeEvery(SIGN_UP_REQUEST, signUpSaga), signInSaga()])
const createAuthChanel = () =>
eventChannel((emit) => {
const callback = (user) => emit({ user })
return firebase.auth().onAuthStateChanged(callback)
})

export function* realtimeSyncSaga() {
const chanel = yield call(createAuthChanel)

while (true) {
const { user } = yield take(chanel)

yield put({
type: SIGN_IN_SUCCESS,
payload: { user }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А если нет user - SIGN_OUT

})
}
}

firebase.auth().onAuthStateChanged((user) => {
if (!user) return
export function* saga() {
yield spawn(realtimeSyncSaga)

window.store.dispatch({
type: SIGN_IN_SUCCESS,
payload: { user }
})
})
yield all([takeEvery(SIGN_UP_REQUEST, signUpSaga), signInSaga()])
}