|
@ -22,45 +22,43 @@ class TopicContainer extends Component { |
|
|
this.props.navigateTo('/404'); |
|
|
this.props.navigateTo('/404'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.getBlockchainData = this.getBlockchainData.bind(this); |
|
|
this.fetchTopicSubject = this.fetchTopicSubject.bind(this); |
|
|
this.fetchTopicSubject = this.fetchTopicSubject.bind(this); |
|
|
this.togglePostingState = this.togglePostingState.bind(this); |
|
|
this.togglePostingState = this.togglePostingState.bind(this); |
|
|
this.postCreated = this.postCreated.bind(this); |
|
|
this.postCreated = this.postCreated.bind(this); |
|
|
|
|
|
|
|
|
var pageStatus = 'initialized'; |
|
|
|
|
|
if (this.props.drizzleStatus['initialized']) { |
|
|
|
|
|
this.dataKey = drizzle.contracts[contract].methods[getTopicMethod].cacheCall(this.props.match.params.topicId); |
|
|
|
|
|
pageStatus = 'loading'; |
|
|
|
|
|
} |
|
|
|
|
|
if (this.dataKey && this.props.contracts[contract][getTopicMethod][this.dataKey]) { |
|
|
|
|
|
pageStatus = 'loaded'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.state = { |
|
|
this.state = { |
|
|
pageStatus: pageStatus, |
|
|
pageStatus: 'initialized', |
|
|
topicID: this.props.match.params.topicId, |
|
|
topicID: parseInt(this.props.match.params.topicId), |
|
|
topicSubject: null, |
|
|
topicSubject: null, |
|
|
postFocus: this.props.match.params.postId && /^[0-9]+$/.test(this.props.match.params.postId) |
|
|
postFocus: this.props.match.params.postId && /^[0-9]+$/.test(this.props.match.params.postId) |
|
|
? this.props.match.params.postId |
|
|
? this.props.match.params.postId |
|
|
: null, |
|
|
: null, |
|
|
fetchTopicSubjectStatus: null, |
|
|
fetchTopicSubjectStatus: 'pending', |
|
|
posting: false |
|
|
posting: false |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
componentDidUpdate() { |
|
|
getBlockchainData() { |
|
|
if (this.state.pageStatus === 'initialized' && |
|
|
if (this.state.pageStatus === 'initialized' && |
|
|
this.props.drizzleStatus['initialized']) { |
|
|
this.props.drizzleStatus['initialized']) { |
|
|
this.dataKey = drizzle.contracts[contract].methods[getTopicMethod].cacheCall(this.state.topicId); |
|
|
this.dataKey = drizzle.contracts[contract].methods[getTopicMethod].cacheCall(this.state.topicID); |
|
|
this.setState({ pageStatus: 'loading' }); |
|
|
this.setState({ pageStatus: 'loading' }); |
|
|
} |
|
|
} |
|
|
if (this.state.pageStatus === 'loading' && |
|
|
if (this.state.pageStatus === 'loading' && |
|
|
this.props.contracts[contract][getTopicMethod][this.dataKey]) { |
|
|
this.props.contracts[contract][getTopicMethod][this.dataKey]) { |
|
|
this.setState({ pageStatus: 'loaded' }); |
|
|
this.setState({ pageStatus: 'loaded' }); |
|
|
if (this.state.fetchTopicSubjectStatus === null){ |
|
|
if (this.props.orbitDB.orbitdb !== null){ |
|
|
this.setState({ fetchTopicSubjectStatus: "fetching"}) |
|
|
this.fetchTopicSubject(this.props.contracts[contract][getTopicMethod][this.dataKey].value[0]); |
|
|
/*this.fetchTopicSubject(this.props.contracts[contract][getTopicMethod][this.dataKey].value[0]);*/ |
|
|
this.setState({ fetchTopicSubjectStatus: 'fetching' }); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (this.state.pageStatus === 'loaded' && |
|
|
|
|
|
this.state.fetchTopicSubjectStatus === 'pending' && |
|
|
|
|
|
this.props.orbitDB.orbitdb !== null) { |
|
|
|
|
|
this.fetchTopicSubject(this.props.contracts[contract][getTopicMethod][this.dataKey].value[0]); |
|
|
|
|
|
this.setState({ fetchTopicSubjectStatus: 'fetching' }); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async fetchTopicSubject(orbitDBAddress) { |
|
|
async fetchTopicSubject(orbitDBAddress) { |
|
@ -85,8 +83,8 @@ class TopicContainer extends Component { |
|
|
|
|
|
|
|
|
this.props.setNavBarTitle(orbitData['subject']); |
|
|
this.props.setNavBarTitle(orbitData['subject']); |
|
|
this.setState({ |
|
|
this.setState({ |
|
|
'topicSubject': orbitData['subject'], |
|
|
topicSubject: orbitData['subject'], |
|
|
fetchTopicSubjectStatus: "fetched" |
|
|
fetchTopicSubjectStatus: 'fetched' |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -137,6 +135,18 @@ class TopicContainer extends Component { |
|
|
</div> |
|
|
</div> |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
|
this.getBlockchainData(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate() { |
|
|
|
|
|
this.getBlockchainData(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() { |
|
|
|
|
|
this.props.setNavBarTitle(''); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators({ |
|
|
const mapDispatchToProps = dispatch => bindActionCreators({ |
|
|