Browse Source

Add events saga

develop
Apostolos Fanakis 4 years ago
parent
commit
2d66195d1f
  1. 4
      packages/concordia-app/src/redux/actions/contractEventActions.js
  2. 12
      packages/concordia-app/src/redux/sagas/eventSaga.js
  3. 2
      packages/concordia-app/src/redux/sagas/rootSaga.js
  4. 14
      packages/concordia-app/src/redux/sagas/userSaga.js
  5. 3
      packages/concordia-app/src/views/Register/index.jsx

4
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';

12
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;

2
packages/concordia-app/src/redux/sagas/rootSaga.js

@ -4,11 +4,13 @@ import { breezeSagas } from '@ezerous/breeze';
import orbitSaga from './orbitSaga'; import orbitSaga from './orbitSaga';
import userSaga from './userSaga'; import userSaga from './userSaga';
import peerDbReplicationSaga from './peerDbReplicationSaga'; import peerDbReplicationSaga from './peerDbReplicationSaga';
import eventSaga from './eventSaga';
export default function* root() { export default function* root() {
const sagas = [ const sagas = [
...drizzleSagas, ...drizzleSagas,
...breezeSagas, ...breezeSagas,
eventSaga,
orbitSaga, orbitSaga,
userSaga, userSaga,
peerDbReplicationSaga, peerDbReplicationSaga,

14
packages/concordia-app/src/redux/sagas/userSaga.js

@ -1,10 +1,11 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import { import {
all, call, put, take, all, call, put, take, takeLatest,
} from 'redux-saga/effects'; } from 'redux-saga/effects';
import { drizzleActions } from '@ezerous/drizzle'; import { drizzleActions } from '@ezerous/drizzle';
import { USER_DATA_UPDATED, USER_DATA_ERROR } from '../actions/userActions'; import { USER_DATA_UPDATED, USER_DATA_ERROR } from '../actions/userActions';
import { FORUM_EVENT_USER_SIGNED_UP } from '../actions/contractEventActions';
function* fetchUserData({ drizzle, account }) { function* fetchUserData({ drizzle, account }) {
const contract = drizzle.contracts.Forum; 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() { function* userSaga() {
const res = yield all([ const res = yield all([
take(drizzleActions.drizzle.DRIZZLE_INITIALIZED), take(drizzleActions.drizzle.DRIZZLE_INITIALIZED),
@ -38,6 +48,8 @@ function* userSaga() {
]); ]);
yield fetchUserData({ drizzle: res[0].drizzle, account: res[1].accounts[0] }); yield fetchUserData({ drizzle: res[0].drizzle, account: res[1].accounts[0] });
yield takeLatest(FORUM_EVENT_USER_SIGNED_UP, userHasSignedUp);
} }
export default userSaga; export default userSaga;

3
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 Register = () => {
const [currentStep, setCurrentStep] = useState('signup'); const [currentStep, setCurrentStep] = useState('signup');
const user = useSelector((state) => state.user); const user = useSelector((state) => state.user);
const [signingUp] = useState(!user.hasSignedUp);
const history = useHistory(); const history = useHistory();
const { t } = useTranslation(); const { t } = useTranslation();
@ -92,7 +93,7 @@ const Register = () => {
</p> </p>
</Card.Description> </Card.Description>
</Card.Content> </Card.Content>
{user.hasSignedUp {user.hasSignedUp && !signingUp
? ( ? (
<> <>
<Card.Content> <Card.Content>

Loading…
Cancel
Save