Browse Source

Replace hardcoded string with constants

develop
Apostolos Fanakis 4 years ago
parent
commit
d8fe90a120
  1. 5
      packages/concordia-app/src/components/PostList/PostListRow/index.jsx
  2. 3
      packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx
  3. 5
      packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js
  4. 6
      packages/concordia-app/src/views/Register/index.jsx
  5. 10
      packages/concordia-app/src/views/Topic/TopicCreate/index.jsx
  6. 3
      packages/concordia-app/src/views/Topic/TopicView/index.jsx

5
packages/concordia-app/src/components/PostList/PostListRow/index.jsx

@ -2,7 +2,7 @@ import React, {
memo, useEffect, useMemo, useState, memo, useEffect, useMemo, useState,
} from 'react'; } from 'react';
import { import {
Dimmer, Grid, List, Loader, Placeholder, Dimmer, Grid, List, Placeholder,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -12,6 +12,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import { breeze } from '../../../redux/store'; import { breeze } from '../../../redux/store';
import './styles.css'; import './styles.css';
import { POSTS_DATABASE } from '../../../constants/OrbitDatabases';
const { orbit } = breeze; const { orbit } = breeze;
@ -42,7 +43,7 @@ const PostListRow = (props) => {
dispatch({ dispatch({
type: FETCH_USER_DATABASE, type: FETCH_USER_DATABASE,
orbit, orbit,
dbName: 'posts', dbName: POSTS_DATABASE,
userAddress: postAuthorAddress, userAddress: postAuthorAddress,
}); });
} }

3
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 { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import { breeze } from '../../../redux/store'; import { breeze } from '../../../redux/store';
import './styles.css'; import './styles.css';
import { TOPICS_DATABASE } from '../../../constants/OrbitDatabases';
const { orbit } = breeze; const { orbit } = breeze;
@ -43,7 +44,7 @@ const TopicListRow = (props) => {
dispatch({ dispatch({
type: FETCH_USER_DATABASE, type: FETCH_USER_DATABASE,
orbit, orbit,
dbName: 'topics', dbName: TOPICS_DATABASE,
userAddress: topicAuthorAddress, userAddress: topicAuthorAddress,
}); });
} }

5
packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js

@ -9,6 +9,7 @@ import {
} from '@ezerous/breeze/src/orbit/orbitActions'; } from '@ezerous/breeze/src/orbit/orbitActions';
import determineKVAddress from '../../utils/orbitUtils'; import determineKVAddress from '../../utils/orbitUtils';
import { FETCH_USER_DATABASE, UPDATE_ORBIT_DATA } from '../actions/peerDbReplicationActions'; import { FETCH_USER_DATABASE, UPDATE_ORBIT_DATA } from '../actions/peerDbReplicationActions';
import { POSTS_DATABASE, TOPICS_DATABASE } from '../../constants/OrbitDatabases';
function* fetchUserDb({ orbit, userAddress, dbName }) { function* fetchUserDb({ orbit, userAddress, dbName }) {
const peerDbAddress = yield call(determineKVAddress, { const peerDbAddress = yield call(determineKVAddress, {
@ -24,7 +25,7 @@ function* updateReduxState({ database }) {
posts: state.orbitData.posts, posts: state.orbitData.posts,
})); }));
if (database.dbname === 'topics') { if (database.dbname === TOPICS_DATABASE) {
const oldTopicsUnchanged = topics const oldTopicsUnchanged = topics
.filter((topic) => !Object .filter((topic) => !Object
.keys(database.all) .keys(database.all)
@ -46,7 +47,7 @@ function* updateReduxState({ database }) {
}); });
} }
if (database.dbname === 'posts') { if (database.dbname === POSTS_DATABASE) {
const oldPostsUnchanged = posts const oldPostsUnchanged = posts
.filter((post) => !Object .filter((post) => !Object
.keys(database.all) .keys(database.all)

6
packages/concordia-app/src/views/Register/index.jsx

@ -19,11 +19,11 @@ const Register = () => {
const goToHomePage = useCallback(() => history.push('/'), [history]); const goToHomePage = useCallback(() => history.push('/'), [history]);
const pushNextStep = useCallback(() => { const pushNextStep = useCallback(() => {
if (currentStep === 'signup') { if (currentStep === REGISTER_STEP_SIGNUP) {
setCurrentStep('profile-information'); setCurrentStep(REGISTER_STEP_PROFILE_INFORMATION);
} }
if (currentStep === 'profile-information') { if (currentStep === REGISTER_STEP_PROFILE_INFORMATION) {
goToHomePage(); goToHomePage();
} }
}, [currentStep, goToHomePage]); }, [currentStep, goToHomePage]);

10
packages/concordia-app/src/views/Topic/TopicCreate/index.jsx

@ -9,6 +9,8 @@ import { useHistory } from 'react-router';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import './styles.css'; import './styles.css';
import { drizzle, breeze } from '../../../redux/store'; 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 { contracts: { Forum: { methods: { createTopic } } } } = drizzle;
const { orbit: { stores } } = breeze; const { orbit: { stores } } = breeze;
@ -47,9 +49,9 @@ const TopicCreate = (props) => {
useEffect(() => { useEffect(() => {
if (posting && transactionStack && transactionStack[createTopicCacheSendStackId] if (posting && transactionStack && transactionStack[createTopicCacheSendStackId]
&& transactions[transactionStack[createTopicCacheSendStackId]]) { && transactions[transactionStack[createTopicCacheSendStackId]]) {
if (transactions[transactionStack[createTopicCacheSendStackId]].status === 'error') { if (transactions[transactionStack[createTopicCacheSendStackId]].status === TRANSACTION_ERROR) {
setPosting(false); setPosting(false);
} else if (transactions[transactionStack[createTopicCacheSendStackId]].status === 'success') { } else if (transactions[transactionStack[createTopicCacheSendStackId]].status === TRANSACTION_SUCCESS) {
const { const {
receipt: { receipt: {
events: { events: {
@ -63,8 +65,8 @@ const TopicCreate = (props) => {
}, },
} = transactions[transactionStack[createTopicCacheSendStackId]]; } = transactions[transactionStack[createTopicCacheSendStackId]];
const topicsDb = Object.values(stores).find((store) => store.dbname === 'topics'); const topicsDb = Object.values(stores).find((store) => store.dbname === TOPICS_DATABASE);
const postsDb = Object.values(stores).find((store) => store.dbname === 'posts'); const postsDb = Object.values(stores).find((store) => store.dbname === POSTS_DATABASE);
topicsDb topicsDb
.put(topicId, { subject: subjectInput }, { pin: true }) .put(topicId, { subject: subjectInput }, { pin: true })

3
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 { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import './styles.css'; import './styles.css';
import PostList from '../../../components/PostList'; import PostList from '../../../components/PostList';
import { TOPICS_DATABASE } from '../../../constants/OrbitDatabases';
const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle; const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const { orbit } = breeze; const { orbit } = breeze;
@ -59,7 +60,7 @@ const TopicView = (props) => {
dispatch({ dispatch({
type: FETCH_USER_DATABASE, type: FETCH_USER_DATABASE,
orbit, orbit,
dbName: 'topics', dbName: TOPICS_DATABASE,
userAddress: getTopicResults[getTopicCallHash].value[0], userAddress: getTopicResults[getTopicCallHash].value[0],
}); });
} }

Loading…
Cancel
Save