Browse Source

Get user DBs and display user avatar in topic view

develop
Apostolos Fanakis 4 years ago
parent
commit
7d5969c8fc
  1. 2
      packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx
  2. 48
      packages/concordia-app/src/views/Topic/TopicView/index.jsx

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

@ -82,7 +82,7 @@ const TopicListRow = (props) => {
} }
}) })
.catch((error) => { .catch((error) => {
console.error('Error during service worker registration:', error); console.error('Error during determination of key-value DB address:', error);
}); });
} }
}, [topicAuthorAddress, users]); }, [topicAuthorAddress, users]);

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

@ -2,14 +2,16 @@ import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { import {
Container, Dimmer, Icon, Placeholder, Step, Container, Dimmer, Icon, Image, Placeholder, Step,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import moment from 'moment'; import moment from 'moment';
import { breeze, drizzle } from '../../../redux/store'; 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'; import { TOPICS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases';
import determineKVAddress from '../../../utils/orbitUtils';
import { PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys';
const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle; const { contracts: { Forum: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle;
const { orbit } = breeze; const { orbit } = breeze;
@ -24,9 +26,11 @@ const TopicView = (props) => {
const userAddress = useSelector((state) => state.user.address); const userAddress = useSelector((state) => state.user.address);
const getTopicResults = useSelector((state) => state.contracts.Forum.getTopic); const getTopicResults = useSelector((state) => state.contracts.Forum.getTopic);
const topics = useSelector((state) => state.orbitData.topics); const topics = useSelector((state) => state.orbitData.topics);
const users = useSelector((state) => state.orbitData.users);
const [getTopicCallHash, setGetTopicCallHash] = useState([]); const [getTopicCallHash, setGetTopicCallHash] = useState([]);
const [topicAuthorAddress, setTopicAuthorAddress] = useState(initialTopicAuthorAddress || null); const [topicAuthorAddress, setTopicAuthorAddress] = useState(initialTopicAuthorAddress || null);
const [topicAuthor, setTopicAuthor] = useState(initialTopicAuthor || null); const [topicAuthor, setTopicAuthor] = useState(initialTopicAuthor || null);
const [topicAuthorMeta, setTopicAuthorMeta] = useState(null);
const [timestamp, setTimestamp] = useState(initialTimestamp || null); const [timestamp, setTimestamp] = useState(initialTimestamp || null);
const [postIds, setPostIds] = useState(initialPostIds || null); const [postIds, setPostIds] = useState(initialPostIds || null);
const [topicSubject, setTopicSubject] = useState(null); const [topicSubject, setTopicSubject] = useState(null);
@ -67,6 +71,30 @@ const TopicView = (props) => {
} }
}, [dispatch, getTopicCallHash, getTopicResults, topicId, topics, userAddress]); }, [dispatch, getTopicCallHash, getTopicResults, topicId, topics, userAddress]);
useEffect(() => {
if (topicAuthorAddress !== null) {
determineKVAddress({ orbit, dbName: USER_DATABASE, userAddress: topicAuthorAddress })
.then((userOrbitAddress) => {
const userFound = users
.find((user) => user.id === userOrbitAddress);
if (userFound) {
setTopicAuthorMeta(userFound);
} else {
dispatch({
type: FETCH_USER_DATABASE,
orbit,
dbName: USER_DATABASE,
userAddress: topicAuthorAddress,
});
}
})
.catch((error) => {
console.error('Error during determination of key-value DB address:', error);
});
}
}, [dispatch, topicAuthorAddress, users]);
useEffect(() => { useEffect(() => {
const topicFound = topics const topicFound = topics
.find((topic) => topic.id === topicId); .find((topic) => topic.id === topicId);
@ -84,7 +112,21 @@ const TopicView = (props) => {
> >
<Step.Group fluid> <Step.Group fluid>
<Step key="topic-header-step-user"> <Step key="topic-header-step-user">
<Icon name="user circle" size="big" inverted color="black" /> {topicAuthorMeta !== null && topicAuthorMeta[PROFILE_PICTURE]
? (
<Image
avatar
src={topicAuthorMeta[PROFILE_PICTURE]}
/>
)
: (
<Icon
name="user circle"
size="big"
inverted
color="black"
/>
)}
<Step.Content> <Step.Content>
<Step.Title> <Step.Title>
{topicAuthor || ( {topicAuthor || (

Loading…
Cancel
Save