|
@ -5,7 +5,6 @@ import { drizzle } from '../index'; |
|
|
|
|
|
|
|
|
import Post from './Post'; |
|
|
import Post from './Post'; |
|
|
import PlaceholderContainer from './PlaceholderContainer'; |
|
|
import PlaceholderContainer from './PlaceholderContainer'; |
|
|
import { determineDBAddress } from '../utils/orbitUtils'; |
|
|
|
|
|
|
|
|
|
|
|
const contract = 'Forum'; |
|
|
const contract = 'Forum'; |
|
|
const getPostMethod = 'getPost'; |
|
|
const getPostMethod = 'getPost'; |
|
@ -17,8 +16,7 @@ class PostList extends Component { |
|
|
this.getBlockchainData = this.getBlockchainData.bind(this); |
|
|
this.getBlockchainData = this.getBlockchainData.bind(this); |
|
|
|
|
|
|
|
|
this.state = { |
|
|
this.state = { |
|
|
dataKeys: [], |
|
|
dataKeys: [] |
|
|
dbAddresses: [] |
|
|
|
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -31,8 +29,8 @@ class PostList extends Component { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getBlockchainData() { |
|
|
getBlockchainData() { |
|
|
const { dataKeys, dbAddresses } = this.state; |
|
|
const { dataKeys } = this.state; |
|
|
const { drizzleStatus, postIDs, contracts } = this.props; |
|
|
const { drizzleStatus, postIDs } = this.props; |
|
|
|
|
|
|
|
|
if (drizzleStatus.initialized) { |
|
|
if (drizzleStatus.initialized) { |
|
|
const dataKeysShallowCopy = dataKeys.slice(); |
|
|
const dataKeysShallowCopy = dataKeys.slice(); |
|
@ -45,17 +43,6 @@ class PostList extends Component { |
|
|
); |
|
|
); |
|
|
fetchingNewData = true; |
|
|
fetchingNewData = true; |
|
|
} |
|
|
} |
|
|
else if (!dbAddresses[postID]){ |
|
|
|
|
|
const fetchedPostData = contracts[contract][getPostMethod][dataKeys[postID]]; |
|
|
|
|
|
if(fetchedPostData) { |
|
|
|
|
|
const dbAddress = await determineDBAddress('posts', fetchedPostData.value[0]); |
|
|
|
|
|
const dbAddressesShallowCopy = dbAddresses.slice(); |
|
|
|
|
|
dbAddressesShallowCopy[postID] = dbAddress; |
|
|
|
|
|
this.setState({ |
|
|
|
|
|
dbAddresses: dbAddressesShallowCopy |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (fetchingNewData) { |
|
|
if (fetchingNewData) { |
|
@ -67,7 +54,7 @@ class PostList extends Component { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const { dataKeys, dbAddresses } = this.state; |
|
|
const { dataKeys } = this.state; |
|
|
const { postIDs, contracts, focusOnPost, recentToTheTop } = this.props; |
|
|
const { postIDs, contracts, focusOnPost, recentToTheTop } = this.props; |
|
|
|
|
|
|
|
|
const posts = postIDs.map((postID, index) => { |
|
|
const posts = postIDs.map((postID, index) => { |
|
@ -75,13 +62,9 @@ class PostList extends Component { |
|
|
if(dataKeys[postID]) |
|
|
if(dataKeys[postID]) |
|
|
fetchedPostData = contracts[contract][getPostMethod][dataKeys[postID]]; |
|
|
fetchedPostData = contracts[contract][getPostMethod][dataKeys[postID]]; |
|
|
|
|
|
|
|
|
const dbAddress = dbAddresses[postID]; |
|
|
if(fetchedPostData) { |
|
|
if(fetchedPostData && dbAddress) { |
|
|
|
|
|
const userAddress = fetchedPostData.value[0]; //Also works as an Orbit Identity ID
|
|
|
|
|
|
|
|
|
|
|
|
const postData = { |
|
|
const postData = { |
|
|
userAddress, |
|
|
userAddress: fetchedPostData.value[0], //Also works as an Orbit Identity ID
|
|
|
fullOrbitAddress: `/orbitdb/${dbAddress}/posts`, |
|
|
|
|
|
userName: fetchedPostData.value[1], |
|
|
userName: fetchedPostData.value[1], |
|
|
timestamp: fetchedPostData.value[2]*1000, |
|
|
timestamp: fetchedPostData.value[2]*1000, |
|
|
topicID: fetchedPostData.value[3] |
|
|
topicID: fetchedPostData.value[3] |
|
|