|
|
@ -23,35 +23,27 @@ class Topic extends Component { |
|
|
|
} |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
const { topicSubjectFetchStatus } = this.state; |
|
|
|
const { topicData, orbitDB, topicID } = this.props; |
|
|
|
|
|
|
|
if (topicData !== null |
|
|
|
&& topicSubjectFetchStatus === 'pending' |
|
|
|
&& orbitDB.ipfsInitialized |
|
|
|
&& orbitDB.orbitdb) { |
|
|
|
this.fetchSubject(topicID); |
|
|
|
} |
|
|
|
this.fetchSubject(this.props.topicID); |
|
|
|
} |
|
|
|
|
|
|
|
componentDidUpdate() { |
|
|
|
this.fetchSubject(this.props.topicID); |
|
|
|
} |
|
|
|
|
|
|
|
async fetchSubject(topicID) { |
|
|
|
const { topicSubjectFetchStatus } = this.state; |
|
|
|
const { topicData, orbitDB, topicID } = this.props; |
|
|
|
const { topicData, user, orbitDB } = this.props; |
|
|
|
|
|
|
|
if (topicData !== null |
|
|
|
&& topicSubjectFetchStatus === 'pending' |
|
|
|
&& orbitDB.ipfsInitialized |
|
|
|
&& orbitDB.orbitdb) { |
|
|
|
this.fetchSubject(topicID); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async fetchSubject(topicID) { |
|
|
|
const { topicData, user, orbitDB } = this.props; |
|
|
|
let topicSubject; |
|
|
|
|
|
|
|
if (topicData.value[1] === user.address) { |
|
|
|
const orbitData = orbitDB.topicsDB.get(topicID); |
|
|
|
if(orbitData) |
|
|
|
topicSubject = orbitData.subject; |
|
|
|
} else { |
|
|
|
const fullAddress = `/orbitdb/${topicData.value[0]}/topics`; |
|
|
@ -59,21 +51,25 @@ class Topic extends Component { |
|
|
|
await store.load(); |
|
|
|
|
|
|
|
const localOrbitData = store.get(topicID); |
|
|
|
if (localOrbitData) { |
|
|
|
if (localOrbitData) |
|
|
|
topicSubject = localOrbitData.subject; |
|
|
|
} else { |
|
|
|
// Wait until we have received something from the network
|
|
|
|
|
|
|
|
store.events.on('replicate', () => { |
|
|
|
console.log("Initiated OrbitDB data replication."); |
|
|
|
}); |
|
|
|
|
|
|
|
store.events.on('replicated', () => { |
|
|
|
console.log("OrbitDB data replicated successfully."); |
|
|
|
topicSubject = store.get(topicID).subject; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.setState({ |
|
|
|
topicSubject, |
|
|
|
topicSubjectFetchStatus: 'fetched' |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
render() { |
|
|
|
const { topicSubject } = this.state; |
|
|
@ -93,7 +89,7 @@ class Topic extends Component { |
|
|
|
> |
|
|
|
<p> |
|
|
|
<strong> |
|
|
|
{topicSubject !== null ? topicSubject |
|
|
|
{(topicSubject) ? topicSubject |
|
|
|
: ( |
|
|
|
<ContentLoader |
|
|
|
height={5.8} |
|
|
@ -147,7 +143,7 @@ Topic.propTypes = { |
|
|
|
history: PropTypes.object.isRequired, |
|
|
|
topicData: GetTopicResult.isRequired, |
|
|
|
orbitDB: PropTypes.object.isRequired, |
|
|
|
topicID: PropTypes.string.isRequired |
|
|
|
topicID: PropTypes.number.isRequired |
|
|
|
}; |
|
|
|
|
|
|
|
const mapStateToProps = state => ({ |
|
|
|