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.profile": "Profile",
"topbar.button.register": "Sign Up",
"topic.create.form.message.field.label": "First post message",
"topic.create.form.message.field.placeholder": "Message",
"topic.create.form.content.field.label": "First post content",
"topic.create.form.content.field.placeholder": "Message",
"topic.create.form.post.button": "Post",
"topic.create.form.subject.field.label": "Topic 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 { POSTS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
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;
@ -65,8 +66,8 @@ const PostListRow = (props) => {
.find((post) => post.id === postId);
if (postFound) {
setPostSubject(postFound.subject);
setPostMessage(postFound.message);
setPostSubject(postFound[POST_SUBJECT]);
setPostMessage(postFound[POST_CONTENT]);
}
}, [postId, posts]);
@ -90,11 +91,11 @@ const PostListRow = (props) => {
return useMemo(() => (
<Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}>
<Feed.Label className="post-profile-picture">
{postAuthorMeta !== null && postAuthorMeta[PROFILE_PICTURE]
{postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE]
? (
<Image
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 { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
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;
@ -66,7 +67,7 @@ const TopicListRow = (props) => {
.find((topic) => topic.id === topicId);
if (topicFound) {
setTopicSubject(topicFound.subject);
setTopicSubject(topicFound[TOPIC_SUBJECT]);
}
}, [topicId, topics]);
@ -94,12 +95,12 @@ const TopicListRow = (props) => {
return (
<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
className="profile-picture"
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 LOCATION = 'location';
export const USER_PROFILE_PICTURE = 'profile_picture';
export const USER_LOCATION = 'location';
const userDatabaseKeys = [
PROFILE_PICTURE,
LOCATION,
USER_PROFILE_PICTURE,
USER_LOCATION,
];
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 { POSTS_DATABASE, TOPICS_DATABASE, USER_DATABASE } from '../../constants/OrbitDatabases';
import userDatabaseKeys from '../../constants/UserDatabaseKeys';
import { TOPIC_SUBJECT } from '../../constants/TopicsDatabaseKeys';
import { POST_CONTENT, POST_SUBJECT } from '../../constants/PostsDatabaseKeys';
function* fetchUserDb({ orbit, userAddress, dbName }) {
const peerDbAddress = yield call(determineKVAddress, {
@ -70,7 +72,7 @@ function* updateReduxState({ database }) {
.entries(database.all)
.map(([key, value]) => ({
id: parseInt(key, 10),
subject: value.subject,
[TOPIC_SUBJECT]: value[TOPIC_SUBJECT],
})),
],
posts: [...posts],
@ -92,8 +94,8 @@ function* updateReduxState({ database }) {
...oldPostsUnchanged,
...Object.entries(database.all).map(([key, value]) => ({
id: parseInt(key, 10),
subject: value.subject,
message: value.message,
[POST_SUBJECT]: value[POST_SUBJECT],
[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 './styles.css';
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;
@ -72,14 +72,14 @@ const PersonalInformationStep = (props) => {
if (profilePictureInput.length > 0) {
keyValuesToStore.push({
key: PROFILE_PICTURE,
key: USER_PROFILE_PICTURE,
value: profilePictureInput,
});
}
if (locationInput.length > 0) {
keyValuesToStore.push({
key: LOCATION,
key: USER_LOCATION,
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 { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../../constants/TransactionStatus';
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 { orbit: { stores } } = breeze;
@ -69,11 +71,11 @@ const TopicCreate = (props) => {
const postsDb = Object.values(stores).find((store) => store.dbname === POSTS_DATABASE);
topicsDb
.put(topicId, { subject: subjectInput }, { pin: true })
.put(topicId, { [TOPIC_SUBJECT]: subjectInput }, { pin: true })
.then(() => postsDb
.put(postId, {
subject: subjectInput,
content: messageInput,
[POST_SUBJECT]: subjectInput,
[POST_CONTENT]: messageInput,
}, { pin: true }))
.then(() => {
history.push(`/topics/${topicId}`);
@ -119,7 +121,7 @@ const TopicCreate = (props) => {
</Form.Field>
<Form.Field required>
<label htmlFor="form-topic-create-field-message">
{t('topic.create.form.message.field.label')}
{t('topic.create.form.content.field.label')}
</label>
<TextArea
id="form-topic-create-field-message"
@ -128,7 +130,7 @@ const TopicCreate = (props) => {
? 'form-textarea-required'
: ''}
value={messageInput}
placeholder={t('topic.create.form.message.field.placeholder')}
placeholder={t('topic.create.form.content.field.placeholder')}
rows={5}
autoheight="true"
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 { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
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 { orbit } = breeze;
@ -100,7 +101,7 @@ const TopicView = (props) => {
.find((topic) => topic.id === topicId);
if (topicFound) {
setTopicSubject(topicFound.subject);
setTopicSubject(topicFound[TOPIC_SUBJECT]);
}
}, [topicId, topics]);
@ -112,11 +113,11 @@ const TopicView = (props) => {
>
<Step.Group fluid>
<Step key="topic-header-step-user">
{topicAuthorMeta !== null && topicAuthorMeta[PROFILE_PICTURE]
{topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
? (
<Image
avatar
src={topicAuthorMeta[PROFILE_PICTURE]}
src={topicAuthorMeta[USER_PROFILE_PICTURE]}
/>
)
: (

Loading…
Cancel
Save