From 2d66195d1f660c998524c65b9b1a0bd30147c03a Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 18 Nov 2020 21:40:16 +0200 Subject: [PATCH] Add events saga --- .../src/redux/actions/contractEventActions.js | 4 ++++ .../concordia-app/src/redux/sagas/eventSaga.js | 12 ++++++++++++ packages/concordia-app/src/redux/sagas/rootSaga.js | 2 ++ packages/concordia-app/src/redux/sagas/userSaga.js | 14 +++++++++++++- .../concordia-app/src/views/Register/index.jsx | 3 ++- 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 packages/concordia-app/src/redux/actions/contractEventActions.js create mode 100644 packages/concordia-app/src/redux/sagas/eventSaga.js diff --git a/packages/concordia-app/src/redux/actions/contractEventActions.js b/packages/concordia-app/src/redux/actions/contractEventActions.js new file mode 100644 index 0000000..9c54288 --- /dev/null +++ b/packages/concordia-app/src/redux/actions/contractEventActions.js @@ -0,0 +1,4 @@ +export const FORUM_EVENT_USER_SIGNED_UP = 'UserSignedUp'; +export const FORUM_EVENT_USERNAME_UPDATED = 'UsernameUpdated'; +export const FORUM_EVENT_TOPIC_CREATED = 'TopicCreated'; +export const FORUM_EVENT_POST_CREATED = 'PostCreated'; diff --git a/packages/concordia-app/src/redux/sagas/eventSaga.js b/packages/concordia-app/src/redux/sagas/eventSaga.js new file mode 100644 index 0000000..5b43d1c --- /dev/null +++ b/packages/concordia-app/src/redux/sagas/eventSaga.js @@ -0,0 +1,12 @@ +import { put, takeEvery } from 'redux-saga/effects'; +import { CONTRACT_EVENT_FIRED } from '@ezerous/drizzle/src/contracts/constants'; + +function* eventBreakDown({ event }) { + yield put({ type: event.event, event: { ...event } }); +} + +function* eventSaga() { + yield takeEvery(CONTRACT_EVENT_FIRED, eventBreakDown); +} + +export default eventSaga; diff --git a/packages/concordia-app/src/redux/sagas/rootSaga.js b/packages/concordia-app/src/redux/sagas/rootSaga.js index 7f5bfb4..dd24291 100644 --- a/packages/concordia-app/src/redux/sagas/rootSaga.js +++ b/packages/concordia-app/src/redux/sagas/rootSaga.js @@ -4,11 +4,13 @@ import { breezeSagas } from '@ezerous/breeze'; import orbitSaga from './orbitSaga'; import userSaga from './userSaga'; import peerDbReplicationSaga from './peerDbReplicationSaga'; +import eventSaga from './eventSaga'; export default function* root() { const sagas = [ ...drizzleSagas, ...breezeSagas, + eventSaga, orbitSaga, userSaga, peerDbReplicationSaga, diff --git a/packages/concordia-app/src/redux/sagas/userSaga.js b/packages/concordia-app/src/redux/sagas/userSaga.js index 6d35de4..92cc840 100644 --- a/packages/concordia-app/src/redux/sagas/userSaga.js +++ b/packages/concordia-app/src/redux/sagas/userSaga.js @@ -1,10 +1,11 @@ /* eslint-disable no-console */ import { - all, call, put, take, + all, call, put, take, takeLatest, } from 'redux-saga/effects'; import { drizzleActions } from '@ezerous/drizzle'; import { USER_DATA_UPDATED, USER_DATA_ERROR } from '../actions/userActions'; +import { FORUM_EVENT_USER_SIGNED_UP } from '../actions/contractEventActions'; function* fetchUserData({ drizzle, account }) { const contract = drizzle.contracts.Forum; @@ -31,6 +32,15 @@ function* fetchUserData({ drizzle, account }) { } } +function* userHasSignedUp({ event }) { + yield put({ + type: USER_DATA_UPDATED, + ...{ + address: event.returnValues.userAddress, username: event.returnValues.username, + }, + }); +} + function* userSaga() { const res = yield all([ take(drizzleActions.drizzle.DRIZZLE_INITIALIZED), @@ -38,6 +48,8 @@ function* userSaga() { ]); yield fetchUserData({ drizzle: res[0].drizzle, account: res[1].accounts[0] }); + + yield takeLatest(FORUM_EVENT_USER_SIGNED_UP, userHasSignedUp); } export default userSaga; diff --git a/packages/concordia-app/src/views/Register/index.jsx b/packages/concordia-app/src/views/Register/index.jsx index e7da27f..d2dac4a 100644 --- a/packages/concordia-app/src/views/Register/index.jsx +++ b/packages/concordia-app/src/views/Register/index.jsx @@ -13,6 +13,7 @@ import { REGISTER_STEP_PROFILE_INFORMATION, REGISTER_STEP_SIGNUP } from '../../c const Register = () => { const [currentStep, setCurrentStep] = useState('signup'); const user = useSelector((state) => state.user); + const [signingUp] = useState(!user.hasSignedUp); const history = useHistory(); const { t } = useTranslation(); @@ -92,7 +93,7 @@ const Register = () => {

- {user.hasSignedUp + {user.hasSignedUp && !signingUp ? ( <>