Browse Source

Extract database keys to constants files

develop
Apostolos Fanakis 4 years ago
parent
commit
e3ceeff318
  1. 4
      packages/concordia-app/public/locales/en/translation.json
  2. 11
      packages/concordia-app/src/components/PostList/PostListRow/index.jsx
  3. 9
      packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx
  4. 9
      packages/concordia-app/src/constants/PostsDatabaseKeys.js
  5. 7
      packages/concordia-app/src/constants/TopicsDatabaseKeys.js
  6. 8
      packages/concordia-app/src/constants/UserDatabaseKeys.js
  7. 8
      packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js
  8. 6
      packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx
  9. 12
      packages/concordia-app/src/views/Topic/TopicCreate/index.jsx
  10. 9
      packages/concordia-app/src/views/Topic/TopicView/index.jsx

4
packages/concordia-app/public/locales/en/translation.json

@ -29,8 +29,8 @@
"topbar.button.create.topic": "Create topic", "topbar.button.create.topic": "Create topic",
"topbar.button.profile": "Profile", "topbar.button.profile": "Profile",
"topbar.button.register": "Sign Up", "topbar.button.register": "Sign Up",
"topic.create.form.message.field.label": "First post message", "topic.create.form.content.field.label": "First post content",
"topic.create.form.message.field.placeholder": "Message", "topic.create.form.content.field.placeholder": "Message",
"topic.create.form.post.button": "Post", "topic.create.form.post.button": "Post",
"topic.create.form.subject.field.label": "Topic subject", "topic.create.form.subject.field.label": "Topic subject",
"topic.create.form.subject.field.placeholder": "Subject", "topic.create.form.subject.field.placeholder": "Subject",

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

@ -14,7 +14,8 @@ import { breeze } from '../../../redux/store';
import './styles.css'; import './styles.css';
import { POSTS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases'; import { POSTS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
import determineKVAddress from '../../../utils/orbitUtils'; import determineKVAddress from '../../../utils/orbitUtils';
import { PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys'; import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../../constants/PostsDatabaseKeys';
const { orbit } = breeze; const { orbit } = breeze;
@ -65,8 +66,8 @@ const PostListRow = (props) => {
.find((post) => post.id === postId); .find((post) => post.id === postId);
if (postFound) { if (postFound) {
setPostSubject(postFound.subject); setPostSubject(postFound[POST_SUBJECT]);
setPostMessage(postFound.message); setPostMessage(postFound[POST_CONTENT]);
} }
}, [postId, posts]); }, [postId, posts]);
@ -90,11 +91,11 @@ const PostListRow = (props) => {
return useMemo(() => ( return useMemo(() => (
<Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}> <Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}>
<Feed.Label className="post-profile-picture"> <Feed.Label className="post-profile-picture">
{postAuthorMeta !== null && postAuthorMeta[PROFILE_PICTURE] {postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE]
? ( ? (
<Image <Image
avatar avatar
src={postAuthorMeta[PROFILE_PICTURE]} src={postAuthorMeta[USER_PROFILE_PICTURE]}
/> />
) )
: ( : (

9
packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx

@ -14,7 +14,8 @@ import { breeze } from '../../../redux/store';
import './styles.css'; import './styles.css';
import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases'; import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
import determineKVAddress from '../../../utils/orbitUtils'; import determineKVAddress from '../../../utils/orbitUtils';
import { PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys'; import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
const { orbit } = breeze; const { orbit } = breeze;
@ -66,7 +67,7 @@ const TopicListRow = (props) => {
.find((topic) => topic.id === topicId); .find((topic) => topic.id === topicId);
if (topicFound) { if (topicFound) {
setTopicSubject(topicFound.subject); setTopicSubject(topicFound[TOPIC_SUBJECT]);
} }
}, [topicId, topics]); }, [topicId, topics]);
@ -94,12 +95,12 @@ const TopicListRow = (props) => {
return ( return (
<Dimmer.Dimmable as={List.Item} onClick={handleTopicClick} blurring dimmed={loading} className="list-item"> <Dimmer.Dimmable as={List.Item} onClick={handleTopicClick} blurring dimmed={loading} className="list-item">
{topicAuthorMeta !== null && topicAuthorMeta[PROFILE_PICTURE] {topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
? ( ? (
<Image <Image
className="profile-picture" className="profile-picture"
avatar avatar
src={topicAuthorMeta[PROFILE_PICTURE]} src={topicAuthorMeta[USER_PROFILE_PICTURE]}
/> />
) )
: ( : (

9
packages/concordia-app/src/constants/PostsDatabaseKeys.js

@ -0,0 +1,9 @@
export const POST_SUBJECT = 'subject';
export const POST_CONTENT = 'content';
const postsDatabaseKeys = [
POST_SUBJECT,
POST_CONTENT,
];
export default postsDatabaseKeys;

7
packages/concordia-app/src/constants/TopicsDatabaseKeys.js

@ -0,0 +1,7 @@
export const TOPIC_SUBJECT = 'subject';
const topicsDatabaseKeys = [
TOPIC_SUBJECT,
];
export default topicsDatabaseKeys;

8
packages/concordia-app/src/constants/UserDatabaseKeys.js

@ -1,9 +1,9 @@
export const PROFILE_PICTURE = 'profile_picture'; export const USER_PROFILE_PICTURE = 'profile_picture';
export const LOCATION = 'location'; export const USER_LOCATION = 'location';
const userDatabaseKeys = [ const userDatabaseKeys = [
PROFILE_PICTURE, USER_PROFILE_PICTURE,
LOCATION, USER_LOCATION,
]; ];
export default userDatabaseKeys; export default userDatabaseKeys;

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

@ -11,6 +11,8 @@ 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, USER_DATABASE } from '../../constants/OrbitDatabases'; import { POSTS_DATABASE, TOPICS_DATABASE, USER_DATABASE } from '../../constants/OrbitDatabases';
import userDatabaseKeys from '../../constants/UserDatabaseKeys'; import userDatabaseKeys from '../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../constants/TopicsDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../constants/PostsDatabaseKeys';
function* fetchUserDb({ orbit, userAddress, dbName }) { function* fetchUserDb({ orbit, userAddress, dbName }) {
const peerDbAddress = yield call(determineKVAddress, { const peerDbAddress = yield call(determineKVAddress, {
@ -70,7 +72,7 @@ function* updateReduxState({ database }) {
.entries(database.all) .entries(database.all)
.map(([key, value]) => ({ .map(([key, value]) => ({
id: parseInt(key, 10), id: parseInt(key, 10),
subject: value.subject, [TOPIC_SUBJECT]: value[TOPIC_SUBJECT],
})), })),
], ],
posts: [...posts], posts: [...posts],
@ -92,8 +94,8 @@ function* updateReduxState({ database }) {
...oldPostsUnchanged, ...oldPostsUnchanged,
...Object.entries(database.all).map(([key, value]) => ({ ...Object.entries(database.all).map(([key, value]) => ({
id: parseInt(key, 10), id: parseInt(key, 10),
subject: value.subject, [POST_SUBJECT]: value[POST_SUBJECT],
message: value.message, [POST_CONTENT]: value[POST_CONTENT],
})), })),
], ],
}); });

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

@ -11,7 +11,7 @@ import checkUrlValid from '../../../utils/urlUtils';
import { breeze } from '../../../redux/store'; import { breeze } from '../../../redux/store';
import './styles.css'; import './styles.css';
import { USER_DATABASE } from '../../../constants/OrbitDatabases'; import { USER_DATABASE } from '../../../constants/OrbitDatabases';
import { LOCATION, PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys'; import { USER_LOCATION, USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
const { orbit: { stores } } = breeze; const { orbit: { stores } } = breeze;
@ -72,14 +72,14 @@ const PersonalInformationStep = (props) => {
if (profilePictureInput.length > 0) { if (profilePictureInput.length > 0) {
keyValuesToStore.push({ keyValuesToStore.push({
key: PROFILE_PICTURE, key: USER_PROFILE_PICTURE,
value: profilePictureInput, value: profilePictureInput,
}); });
} }
if (locationInput.length > 0) { if (locationInput.length > 0) {
keyValuesToStore.push({ keyValuesToStore.push({
key: LOCATION, key: USER_LOCATION,
value: locationInput, value: locationInput,
}); });
} }

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

@ -11,6 +11,8 @@ import './styles.css';
import { drizzle, breeze } from '../../../redux/store'; import { drizzle, breeze } from '../../../redux/store';
import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus'; import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus';
import { POSTS_DATABASE, TOPICS_DATABASE } from '../../../constants/OrbitDatabases'; import { POSTS_DATABASE, TOPICS_DATABASE } from '../../../constants/OrbitDatabases';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../../constants/PostsDatabaseKeys';
const { contracts: { Forum: { methods: { createTopic } } } } = drizzle; const { contracts: { Forum: { methods: { createTopic } } } } = drizzle;
const { orbit: { stores } } = breeze; const { orbit: { stores } } = breeze;
@ -69,11 +71,11 @@ const TopicCreate = (props) => {
const postsDb = Object.values(stores).find((store) => store.dbname === POSTS_DATABASE); const postsDb = Object.values(stores).find((store) => store.dbname === POSTS_DATABASE);
topicsDb topicsDb
.put(topicId, { subject: subjectInput }, { pin: true }) .put(topicId, { [TOPIC_SUBJECT]: subjectInput }, { pin: true })
.then(() => postsDb .then(() => postsDb
.put(postId, { .put(postId, {
subject: subjectInput, [POST_SUBJECT]: subjectInput,
content: messageInput, [POST_CONTENT]: messageInput,
}, { pin: true })) }, { pin: true }))
.then(() => { .then(() => {
history.push(`/topics/${topicId}`); history.push(`/topics/${topicId}`);
@ -119,7 +121,7 @@ const TopicCreate = (props) => {
</Form.Field> </Form.Field>
<Form.Field required> <Form.Field required>
<label htmlFor="form-topic-create-field-message"> <label htmlFor="form-topic-create-field-message">
{t('topic.create.form.message.field.label')} {t('topic.create.form.content.field.label')}
</label> </label>
<TextArea <TextArea
id="form-topic-create-field-message" id="form-topic-create-field-message"
@ -128,7 +130,7 @@ const TopicCreate = (props) => {
? 'form-textarea-required' ? 'form-textarea-required'
: ''} : ''}
value={messageInput} value={messageInput}
placeholder={t('topic.create.form.message.field.placeholder')} placeholder={t('topic.create.form.content.field.placeholder')}
rows={5} rows={5}
autoheight="true" autoheight="true"
onChange={handleSubjectInputChange} onChange={handleSubjectInputChange}

9
packages/concordia-app/src/views/Topic/TopicView/index.jsx

@ -11,7 +11,8 @@ import './styles.css';
import PostList from '../../../components/PostList'; import PostList from '../../../components/PostList';
import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases'; import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
import determineKVAddress from '../../../utils/orbitUtils'; import determineKVAddress from '../../../utils/orbitUtils';
import { PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys'; import { USER_PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../../constants/TopicsDatabaseKeys';
const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle; const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const { orbit } = breeze; const { orbit } = breeze;
@ -100,7 +101,7 @@ const TopicView = (props) => {
.find((topic) => topic.id === topicId); .find((topic) => topic.id === topicId);
if (topicFound) { if (topicFound) {
setTopicSubject(topicFound.subject); setTopicSubject(topicFound[TOPIC_SUBJECT]);
} }
}, [topicId, topics]); }, [topicId, topics]);
@ -112,11 +113,11 @@ const TopicView = (props) => {
> >
<Step.Group fluid> <Step.Group fluid>
<Step key="topic-header-step-user"> <Step key="topic-header-step-user">
{topicAuthorMeta !== null && topicAuthorMeta[PROFILE_PICTURE] {topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
? ( ? (
<Image <Image
avatar avatar
src={topicAuthorMeta[PROFILE_PICTURE]} src={topicAuthorMeta[USER_PROFILE_PICTURE]}
/> />
) )
: ( : (

Loading…
Cancel
Save