Skip to content
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

Ht5 #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Ht5 #21

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
50 changes: 40 additions & 10 deletions admin/src/components/people/people-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ 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,20 +15,48 @@ class PeopleList extends Component {

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

rowRenderer = ({ style, index, key }) => {
const person = this.props.people[index]
willEnter = () => ({
opacity: 0
})

willLeave = () => ({
opacity: spring(0, { stiffness: 20, damping: 40 })
})

get styles() {
return this.props.people.map((people) => ({
key: people.uid,
style: {
opacity: spring(1, { stiffness: 50, damping: 40 })
},
data: people
}))
}

rowRenderer = (interpolated) => ({ style, index, key }) => {
const rowCtx = interpolated[index]
const person = rowCtx.data
return (
<div style={style} key={key}>
<div style={{ ...style, ...rowCtx.style }} key={key}>
<PersonCard person={person} />
</div>
)
Expand Down
38 changes: 30 additions & 8 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 { takeEvery, put, call, apply, take, all } from 'redux-saga/effects'
import {
takeEvery,
put,
call,
apply,
take,
all,
spawn
} from 'redux-saga/effects'
import { eventChannel } from 'redux-saga'

/**
* Constants
Expand Down Expand Up @@ -115,15 +124,28 @@ export function* signInSaga() {
})
}

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

firebase.auth().onAuthStateChanged((user) => {
if (user) {
window.store.dispatch({
function* authSaga() {
const channel = yield createEventChannel()
while (true) {
const { user } = yield take(channel)
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 делать

yield put({
type: SIGN_IN_SUCCESS,
payload: { user }
})
}
})
}

export function* saga() {
yield spawn(authSaga)

yield all([takeEvery(SIGN_UP_REQUEST, signUpSaga), signInSaga()])
}