|
@ -2,7 +2,7 @@ import React, { |
|
|
memo, useEffect, useMemo, useState, |
|
|
memo, useEffect, useMemo, useState, |
|
|
} from 'react'; |
|
|
} from 'react'; |
|
|
import { |
|
|
import { |
|
|
Dimmer, Grid, List, Placeholder, |
|
|
Dimmer, Grid, Image, 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,7 +12,9 @@ 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'; |
|
|
import { POSTS_DATABASE, USER_DATABASE } from '../../../constants/OrbitDatabases'; |
|
|
|
|
|
import determineKVAddress from '../../../utils/orbitUtils'; |
|
|
|
|
|
import { PROFILE_PICTURE } from '../../../constants/UserDatabaseKeys'; |
|
|
|
|
|
|
|
|
const { orbit } = breeze; |
|
|
const { orbit } = breeze; |
|
|
|
|
|
|
|
@ -24,8 +26,10 @@ const PostListRow = (props) => { |
|
|
const [timeAgo, setTimeAgo] = useState(null); |
|
|
const [timeAgo, setTimeAgo] = useState(null); |
|
|
const [postSubject, setPostSubject] = useState(null); |
|
|
const [postSubject, setPostSubject] = useState(null); |
|
|
const [postMessage, setPostMessage] = useState(null); |
|
|
const [postMessage, setPostMessage] = useState(null); |
|
|
|
|
|
const [postAuthorMeta, setPostAuthorMeta] = useState(null); |
|
|
const userAddress = useSelector((state) => state.user.address); |
|
|
const userAddress = useSelector((state) => state.user.address); |
|
|
const posts = useSelector((state) => state.orbitData.posts); |
|
|
const posts = useSelector((state) => state.orbitData.posts); |
|
|
|
|
|
const users = useSelector((state) => state.orbitData.users); |
|
|
const dispatch = useDispatch(); |
|
|
const dispatch = useDispatch(); |
|
|
const history = useHistory(); |
|
|
const history = useHistory(); |
|
|
const { t } = useTranslation(); |
|
|
const { t } = useTranslation(); |
|
@ -46,6 +50,13 @@ const PostListRow = (props) => { |
|
|
dbName: POSTS_DATABASE, |
|
|
dbName: POSTS_DATABASE, |
|
|
userAddress: postAuthorAddress, |
|
|
userAddress: postAuthorAddress, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
dispatch({ |
|
|
|
|
|
type: FETCH_USER_DATABASE, |
|
|
|
|
|
orbit, |
|
|
|
|
|
dbName: USER_DATABASE, |
|
|
|
|
|
userAddress: postAuthorAddress, |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
}, [dispatch, postAuthorAddress, userAddress]); |
|
|
}, [dispatch, postAuthorAddress, userAddress]); |
|
|
|
|
|
|
|
@ -59,10 +70,43 @@ const PostListRow = (props) => { |
|
|
} |
|
|
} |
|
|
}, [postId, posts]); |
|
|
}, [postId, posts]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
if (postAuthorAddress !== null) { |
|
|
|
|
|
determineKVAddress({ orbit, dbName: USER_DATABASE, userAddress: postAuthorAddress }) |
|
|
|
|
|
.then((userOrbitAddress) => { |
|
|
|
|
|
const userFound = users |
|
|
|
|
|
.find((user) => user.id === userOrbitAddress); |
|
|
|
|
|
|
|
|
|
|
|
if (userFound) { |
|
|
|
|
|
setPostAuthorMeta(userFound); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
console.error('Error during determination of key-value DB address:', error); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}, [postAuthorAddress, users]); |
|
|
|
|
|
|
|
|
return useMemo(() => ( |
|
|
return useMemo(() => ( |
|
|
<Dimmer.Dimmable as={List.Item} blurring dimmed={loading} className="list-item"> |
|
|
<Dimmer.Dimmable as={List.Item} blurring dimmed={loading} className="list-item"> |
|
|
<List.Icon name="user circle" size="big" inverted color="black" verticalAlign="middle" /> |
|
|
{postAuthorMeta !== null && postAuthorMeta[PROFILE_PICTURE] |
|
|
<List.Content> |
|
|
? ( |
|
|
|
|
|
<Image |
|
|
|
|
|
className="profile-picture" |
|
|
|
|
|
avatar |
|
|
|
|
|
src={postAuthorMeta[PROFILE_PICTURE]} |
|
|
|
|
|
/> |
|
|
|
|
|
) |
|
|
|
|
|
: ( |
|
|
|
|
|
<List.Icon |
|
|
|
|
|
name="user circle" |
|
|
|
|
|
size="big" |
|
|
|
|
|
inverted |
|
|
|
|
|
color="black" |
|
|
|
|
|
verticalAlign="middle" |
|
|
|
|
|
/> |
|
|
|
|
|
)} |
|
|
|
|
|
<List.Content className="list-content"> |
|
|
<List.Header> |
|
|
<List.Header> |
|
|
<Grid> |
|
|
<Grid> |
|
|
<Grid.Column floated="left" width={14}> |
|
|
<Grid.Column floated="left" width={14}> |
|
@ -87,8 +131,11 @@ const PostListRow = (props) => { |
|
|
</Grid> |
|
|
</Grid> |
|
|
</List.Description> |
|
|
</List.Description> |
|
|
</List.Content> |
|
|
</List.Content> |
|
|
|
|
|
<List.Content> |
|
|
|
|
|
{postMessage} |
|
|
|
|
|
</List.Content> |
|
|
</Dimmer.Dimmable> |
|
|
</Dimmer.Dimmable> |
|
|
), [loading, postAuthor, postId, postSubject, t, timeAgo]); |
|
|
), [loading, postAuthor, postAuthorMeta, postId, postMessage, postSubject, t, timeAgo]); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
PostListRow.defaultProps = { |
|
|
PostListRow.defaultProps = { |
|
|