From 4058c55dcf23cbfac1b42657ca88633cefb9e168 Mon Sep 17 00:00:00 2001 From: Ivan Sam Date: Sun, 12 Nov 2017 11:37:53 -0300 Subject: [PATCH 1/3] =?UTF-8?q?HT5.1=20=D0=9E=D1=82=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=8F=D1=82=D1=8C=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D1=83=20=D0=BD=D0=B0=20=D1=8E=D0=B7=D0=B5=D1=80=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D1=83=D1=85=D0=BE=D0=B4=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=20/people?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ducks/people.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ducks/people.js b/src/ducks/people.js index 509323e..d73267f 100644 --- a/src/ducks/people.js +++ b/src/ducks/people.js @@ -6,6 +6,7 @@ import {delay, eventChannel} from 'redux-saga' import firebase from 'firebase' import {createSelector} from 'reselect' import {fbToEntities} from './utils' +import {LOCATION_CHANGE} from 'react-router-redux'; /** * Constants @@ -171,6 +172,20 @@ export const cancelableSyncSaga = function * () { */ } +export const cancelableRealtimePeopleSyncSaga = function * () { + let task + + while (true) { + const {payload} = yield take(LOCATION_CHANGE) + if (payload.pathname.includes('people') || payload.pathname.includes('admin')) { + task = yield fork(realtimePeopleSyncSaga) + + } else if (task) { + yield cancel(task) + } + } +} + const createPeopleSocket = () => eventChannel(emit => { const ref = firebase.database().ref('people') const callback = data => emit({ data }) @@ -183,18 +198,23 @@ const createPeopleSocket = () => eventChannel(emit => { export const realtimePeopleSyncSaga = function * () { const chan = yield call(createPeopleSocket) - while (true) { + try { const { data } = yield take(chan) yield put({ type: FETCH_ALL_SUCCESS, payload: data.val() }) + } finally { + if (yield cancelled()) { + yield call([chan, chan.close]) + console.log('---', 'realtime saga was cancelled') + } } } export function * saga() { - yield spawn(realtimePeopleSyncSaga) + yield spawn(cancelableRealtimePeopleSyncSaga) yield all([ takeEvery(ADD_PERSON_REQUEST, addPersonSaga), From abf1e699fa39d65eb14592a9b46fc3a7dbde38ae Mon Sep 17 00:00:00 2001 From: Ivan Sam Date: Sun, 12 Nov 2017 20:10:25 -0300 Subject: [PATCH 2/3] =?UTF-8?q?HT5.2=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0=D1=86=D0=B8=D1=8E?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=87=D0=B5=D0=BB=D0=BE=D0=B2=D0=B5=D0=BA=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=20/people?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/people/PersonRow.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/people/PersonRow.js b/src/components/people/PersonRow.js index 0db66ae..c4318ed 100644 --- a/src/components/people/PersonRow.js +++ b/src/components/people/PersonRow.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import {DragSource} from 'react-dnd' import {getEmptyImage} from 'react-dnd-html5-backend' import DragPreview from './PersonDragPreview' +import {Motion, spring} from 'react-motion' class PersonRow extends Component { static propTypes = { @@ -13,12 +14,19 @@ class PersonRow extends Component { } render() { - const {style, person, connectDragSource, isDragging} = this.props + const {style, person, connectDragSource} = this.props return ( -
- {connectDragSource(

{person.firstName} {person.lastName}

)} -

{person.email}

-
+ + {interpolatingStyle => ( +
+ {connectDragSource(

{person.firstName} {person.lastName}

)} +

{person.email}

+
+ )} +
) } } From b6cd9b9678305732de02c82677c224bf5c1659c6 Mon Sep 17 00:00:00 2001 From: Ivan Sam Date: Sun, 12 Nov 2017 20:59:42 -0300 Subject: [PATCH 3/3] =?UTF-8?q?HT5.3=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B0=D1=82=D1=8C=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BD=D0=B0=20eventChan?= =?UTF-8?q?nel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ducks/auth.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ducks/auth.js b/src/ducks/auth.js index 09ebeda..afd320a 100644 --- a/src/ducks/auth.js +++ b/src/ducks/auth.js @@ -2,7 +2,8 @@ import {appName} from '../config' import {Record} from 'immutable' import firebase from 'firebase' import {createSelector} from 'reselect' -import {call, put, all, take} from 'redux-saga/effects' +import {eventChannel} from 'redux-saga' +import {call, put, all, take, spawn} from 'redux-saga/effects' import {replace} from 'react-router-redux' /** @@ -69,6 +70,7 @@ export function signIn(email, password) { } } +/* firebase.auth().onAuthStateChanged(user => { if (!user) return @@ -77,6 +79,7 @@ firebase.auth().onAuthStateChanged(user => { payload: { user } }) }) +*/ /** * Sagas @@ -126,11 +129,22 @@ export const signInSaga = function * () { } } +const createAuthSocket = () => eventChannel(emit => firebase.auth().onAuthStateChanged(user => emit({ user }))) + export function * watchStatusChangeSaga() { + const chan = yield call(createAuthSocket) + while (true) { - yield take(SIGN_IN_SUCCESS) + const { user } = yield take(chan) + + if (user) { + yield put({ + type: SIGN_IN_SUCCESS, + payload: { user } + }) - yield (put(replace('/admin'))) + yield (put(replace('/admin'))) + } } }