|
@ -12,24 +12,37 @@ class PostList extends Component { |
|
|
super(props); |
|
|
super(props); |
|
|
|
|
|
|
|
|
this.getBlockchainData = this.getBlockchainData.bind(this); |
|
|
this.getBlockchainData = this.getBlockchainData.bind(this); |
|
|
this.dataKeys = []; |
|
|
|
|
|
|
|
|
this.state = { |
|
|
|
|
|
dataKeys: [] |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getBlockchainData(){ |
|
|
getBlockchainData(){ |
|
|
if (this.props.drizzleStatus['initialized']){ |
|
|
if (this.props.drizzleStatus['initialized']){ |
|
|
|
|
|
let dataKeysShallowCopy = this.state.dataKeys.slice(); |
|
|
|
|
|
let fetchingNewData = false; |
|
|
|
|
|
|
|
|
this.props.postIDs.forEach( postID => { |
|
|
this.props.postIDs.forEach( postID => { |
|
|
if (!this.dataKeys[postID]) { |
|
|
if (!this.state.dataKeys[postID]) { |
|
|
this.dataKeys[postID] = drizzle.contracts[contract].methods[getPostMethod].cacheCall(postID); |
|
|
dataKeysShallowCopy[postID] = drizzle.contracts[contract].methods[getPostMethod].cacheCall(postID); |
|
|
|
|
|
fetchingNewData = true; |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (fetchingNewData){ |
|
|
|
|
|
this.setState({ |
|
|
|
|
|
dataKeys: dataKeysShallowCopy |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const posts = this.props.postIDs.map((postID, index) => { |
|
|
const posts = this.props.postIDs.map((postID, index) => { |
|
|
return (<Post |
|
|
return (<Post |
|
|
postData={(this.dataKeys[postID] && this.props.contracts[contract][getPostMethod][this.dataKeys[postID]]) |
|
|
postData={(this.state.dataKeys[postID] && this.props.contracts[contract][getPostMethod][this.state.dataKeys[postID]]) |
|
|
? this.props.contracts[contract][getPostMethod][this.dataKeys[postID]] |
|
|
? this.props.contracts[contract][getPostMethod][this.state.dataKeys[postID]] |
|
|
: null} |
|
|
: null} |
|
|
avatarUrl={""} |
|
|
avatarUrl={""} |
|
|
postIndex={index} |
|
|
postIndex={index} |
|
|