From d8fe90a1203b40c2171159d953525f315301a2ac Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sun, 15 Nov 2020 17:27:22 +0200 Subject: [PATCH] Replace hardcoded string with constants --- .../src/components/PostList/PostListRow/index.jsx | 5 +++-- .../src/components/TopicList/TopicListRow/index.jsx | 3 ++- .../src/redux/sagas/peerDbReplicationSaga.js | 5 +++-- packages/concordia-app/src/views/Register/index.jsx | 6 +++--- .../src/views/Topic/TopicCreate/index.jsx | 10 ++++++---- .../concordia-app/src/views/Topic/TopicView/index.jsx | 3 ++- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx index b03d475..e9208c0 100644 --- a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx +++ b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx @@ -2,7 +2,7 @@ import React, { memo, useEffect, useMemo, useState, } from 'react'; import { - Dimmer, Grid, List, Loader, Placeholder, + Dimmer, Grid, List, Placeholder, } from 'semantic-ui-react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; @@ -12,6 +12,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { breeze } from '../../../redux/store'; import './styles.css'; +import { POSTS_DATABASE } from '../../../constants/OrbitDatabases'; const { orbit } = breeze; @@ -42,7 +43,7 @@ const PostListRow = (props) => { dispatch({ type: FETCH_USER_DATABASE, orbit, - dbName: 'posts', + dbName: POSTS_DATABASE, userAddress: postAuthorAddress, }); } diff --git a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx b/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx index 758cb68..f20a06a 100644 --- a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx +++ b/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx @@ -12,6 +12,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { breeze } from '../../../redux/store'; import './styles.css'; +import { TOPICS_DATABASE } from '../../../constants/OrbitDatabases'; const { orbit } = breeze; @@ -43,7 +44,7 @@ const TopicListRow = (props) => { dispatch({ type: FETCH_USER_DATABASE, orbit, - dbName: 'topics', + dbName: TOPICS_DATABASE, userAddress: topicAuthorAddress, }); } diff --git a/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js b/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js index a7713d9..3b94829 100644 --- a/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js +++ b/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js @@ -9,6 +9,7 @@ import { } from '@ezerous/breeze/src/orbit/orbitActions'; import determineKVAddress from '../../utils/orbitUtils'; import { FETCH_USER_DATABASE, UPDATE_ORBIT_DATA } from '../actions/peerDbReplicationActions'; +import { POSTS_DATABASE, TOPICS_DATABASE } from '../../constants/OrbitDatabases'; function* fetchUserDb({ orbit, userAddress, dbName }) { const peerDbAddress = yield call(determineKVAddress, { @@ -24,7 +25,7 @@ function* updateReduxState({ database }) { posts: state.orbitData.posts, })); - if (database.dbname === 'topics') { + if (database.dbname === TOPICS_DATABASE) { const oldTopicsUnchanged = topics .filter((topic) => !Object .keys(database.all) @@ -46,7 +47,7 @@ function* updateReduxState({ database }) { }); } - if (database.dbname === 'posts') { + if (database.dbname === POSTS_DATABASE) { const oldPostsUnchanged = posts .filter((post) => !Object .keys(database.all) diff --git a/packages/concordia-app/src/views/Register/index.jsx b/packages/concordia-app/src/views/Register/index.jsx index ef5e36e..e7da27f 100644 --- a/packages/concordia-app/src/views/Register/index.jsx +++ b/packages/concordia-app/src/views/Register/index.jsx @@ -19,11 +19,11 @@ const Register = () => { const goToHomePage = useCallback(() => history.push('/'), [history]); const pushNextStep = useCallback(() => { - if (currentStep === 'signup') { - setCurrentStep('profile-information'); + if (currentStep === REGISTER_STEP_SIGNUP) { + setCurrentStep(REGISTER_STEP_PROFILE_INFORMATION); } - if (currentStep === 'profile-information') { + if (currentStep === REGISTER_STEP_PROFILE_INFORMATION) { goToHomePage(); } }, [currentStep, goToHomePage]); diff --git a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx index 4df7a2e..32410f0 100644 --- a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx @@ -9,6 +9,8 @@ import { useHistory } from 'react-router'; import { useSelector } from 'react-redux'; import './styles.css'; import { drizzle, breeze } from '../../../redux/store'; +import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus'; +import { POSTS_DATABASE, TOPICS_DATABASE } from '../../../constants/OrbitDatabases'; const { contracts: { Forum: { methods: { createTopic } } } } = drizzle; const { orbit: { stores } } = breeze; @@ -47,9 +49,9 @@ const TopicCreate = (props) => { useEffect(() => { if (posting && transactionStack && transactionStack[createTopicCacheSendStackId] && transactions[transactionStack[createTopicCacheSendStackId]]) { - if (transactions[transactionStack[createTopicCacheSendStackId]].status === 'error') { + if (transactions[transactionStack[createTopicCacheSendStackId]].status === TRANSACTION_ERROR) { setPosting(false); - } else if (transactions[transactionStack[createTopicCacheSendStackId]].status === 'success') { + } else if (transactions[transactionStack[createTopicCacheSendStackId]].status === TRANSACTION_SUCCESS) { const { receipt: { events: { @@ -63,8 +65,8 @@ const TopicCreate = (props) => { }, } = transactions[transactionStack[createTopicCacheSendStackId]]; - const topicsDb = Object.values(stores).find((store) => store.dbname === 'topics'); - const postsDb = Object.values(stores).find((store) => store.dbname === 'posts'); + const topicsDb = Object.values(stores).find((store) => store.dbname === TOPICS_DATABASE); + const postsDb = Object.values(stores).find((store) => store.dbname === POSTS_DATABASE); topicsDb .put(topicId, { subject: subjectInput }, { pin: true }) diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index c5e4687..446ba31 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicView/index.jsx @@ -9,6 +9,7 @@ import { breeze, drizzle } from '../../../redux/store'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import './styles.css'; import PostList from '../../../components/PostList'; +import { TOPICS_DATABASE } from '../../../constants/OrbitDatabases'; const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle; const { orbit } = breeze; @@ -59,7 +60,7 @@ const TopicView = (props) => { dispatch({ type: FETCH_USER_DATABASE, orbit, - dbName: 'topics', + dbName: TOPICS_DATABASE, userAddress: getTopicResults[getTopicCallHash].value[0], }); }