import { drizzleConnect } from 'drizzle-react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import WithBlockchainData from '../components/WithBlockchainData';
import PostList from '../components/PostList';
import NewPost from '../components/NewPost';
import FloatingButton from '../components/FloatingButton';
import LoadingSpinner from '../components/LoadingSpinner';
class Topic extends Component {
constructor(props, context) {
super(props);
this.fetchTopicSubject = this.fetchTopicSubject.bind(this);
this.handleClick = this.handleClick.bind(this);
this.postCreated = this.postCreated.bind(this);
this.drizzle = context.drizzle;
this.state = {
topicID: this.props.params.topicId,
topicSubject: this.props.params.topicSubject ? this.props.params.topicSubject : null,
postFocus: this.props.params.postId && /^[0-9]+$/.test(this.props.params.postId)
? this.props.params.postId
: null,
getPostsTransactionState: null,
posting: false
};
}
async fetchTopicSubject(orbitDBAddress) {
/*const fullAddress = this.topicsData[this.state.topicID][1];
const store = await this.props.orbitDB.orbitdb.keyvalue(JSON.stringify(fullAddress));
await store.load();
var som = store.get(JSON.stringify(this.state.topicID));
this.topicsSubjects[this.state.topicID] = som['subject'];
this.topicsSubjectsFetchStatus[this.state.topicID] = "fetched";*/
var som =this.props.orbitDB.topicsDB.get(this.state.topicID);
this.setState({'topicSubject': som['subject']});
}
handleClick(event) {
if (event){
event.preventDefault();
}
this.setState(prevState => ({
posting: !prevState.posting
}));
}
postCreated(){
this.setState(prevState => ({
getPostsTransactionState: null,
posting: false
}));
}
render() {
var topicContents;
if (this.state.getPostsTransactionState !== "SUCCESS") {
topicContents = (