Browse Source

Fix topics and posts not loading bug, Add click listener for new posts in sidebar messages

develop
Apostolos Fanakis 6 years ago
parent
commit
025d99e1e7
  1. 23
      app/src/components/PostList.js
  2. 25
      app/src/components/TopicList.js
  3. 8
      app/src/containers/TransactionsMonitorContainer.js

23
app/src/components/PostList.js

@ -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}

25
app/src/components/TopicList.js

@ -12,24 +12,37 @@ class TopicList 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.topicIDs.forEach( topicID => { this.props.topicIDs.forEach( topicID => {
if (!this.dataKeys[topicID]) { if (!this.state.dataKeys[topicID]) {
this.dataKeys[topicID] = drizzle.contracts[contract].methods[getTopicMethod].cacheCall(topicID); dataKeysShallowCopy[topicID] = drizzle.contracts[contract].methods[getTopicMethod].cacheCall(topicID);
fetchingNewData = true;
} }
}) })
if (fetchingNewData){
this.setState({
dataKeys: dataKeysShallowCopy
});
}
} }
} }
render() { render() {
const topics = this.props.topicIDs.map((topicID) => { const topics = this.props.topicIDs.map( topicID => {
return (<Topic return (<Topic
topicData={(this.dataKeys[topicID] && this.props.contracts[contract][getTopicMethod][this.dataKeys[topicID]]) topicData={(this.state.dataKeys[topicID] && this.props.contracts[contract][getTopicMethod][this.state.dataKeys[topicID]])
? this.props.contracts[contract][getTopicMethod][this.dataKeys[topicID]] ? this.props.contracts[contract][getTopicMethod][this.state.dataKeys[topicID]]
: null} : null}
topicID={topicID} topicID={topicID}
key={topicID} />) key={topicID} />)

8
app/src/containers/TransactionsMonitorContainer.js

@ -39,6 +39,14 @@ class RightSideBar extends Component {
); );
this.handleMessageDismiss(null, index); this.handleMessageDismiss(null, index);
break; break;
case 'PostCreated':
this.props.history.push("/topic/" +
this.props.transactions[transactionHash].receipt.events.PostCreated.returnValues.topicID +
"/" +
this.props.transactions[transactionHash].receipt.events.PostCreated.returnValues.postID
);
this.handleMessageDismiss(null, index);
break;
default: default:
this.handleMessageDismiss(null, index); this.handleMessageDismiss(null, index);
break; break;

Loading…
Cancel
Save