|
@ -10,6 +10,7 @@ import epochTimeConverter from '../helpers/EpochTimeConverter'; |
|
|
|
|
|
|
|
|
const contract = "Forum"; |
|
|
const contract = "Forum"; |
|
|
const contractMethods = { |
|
|
const contractMethods = { |
|
|
|
|
|
getUsername: "getUsername", |
|
|
getDateOfRegister: "getUserDateOfRegister", |
|
|
getDateOfRegister: "getUserDateOfRegister", |
|
|
getOrbitDB: "getOrbitDBId", |
|
|
getOrbitDB: "getOrbitDBId", |
|
|
getUserTopics: "getUserTopics", |
|
|
getUserTopics: "getUserTopics", |
|
@ -20,10 +21,20 @@ class Profile extends Component { |
|
|
constructor(props, context) { |
|
|
constructor(props, context) { |
|
|
super(props); |
|
|
super(props); |
|
|
|
|
|
|
|
|
//THIS WILL CHANGE WITH ACTUAL DATA
|
|
|
if (this.props.params.address){ |
|
|
this.match = { |
|
|
this.profile = { |
|
|
|
|
|
userAddress: this.props.params.address, |
|
|
|
|
|
username: this.props.params.username ? this.props.params.username : "", |
|
|
|
|
|
orbitId: "", |
|
|
|
|
|
self: false |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
this.profile = { |
|
|
|
|
|
userAddress: this.props.user.address, |
|
|
username: this.props.user.username, |
|
|
username: this.props.user.username, |
|
|
userAddress: this.props.user.address |
|
|
orbitId: this.props.orbitDB.id, |
|
|
|
|
|
self: true |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.handleTabClick = this.handleTabClick.bind(this); |
|
|
this.handleTabClick = this.handleTabClick.bind(this); |
|
@ -32,12 +43,13 @@ class Profile extends Component { |
|
|
|
|
|
|
|
|
this.state = { |
|
|
this.state = { |
|
|
viewSelected: "topics", |
|
|
viewSelected: "topics", |
|
|
username: this.match.username, // TODO actually get them from match
|
|
|
username: this.profile.username, |
|
|
userAddress: this.match.userAddress, // when router is fixed
|
|
|
userAddress: this.profile.userAddress, |
|
|
dateOfRegister: null, |
|
|
dateOfRegister: null, |
|
|
orbitDBId: this.match.address === this.props.user.address ? this.props.orbitDB.id : "", |
|
|
orbitDBId: this.profile.orbitId, |
|
|
|
|
|
getUsernameTransactionState: null, |
|
|
getDateOfRegisterTransactionState: null, |
|
|
getDateOfRegisterTransactionState: null, |
|
|
getOrbitDBTransactionState: this.match.address === this.props.user.address ? "SUCCESS" : null, |
|
|
getOrbitDBTransactionState: this.profile.orbitId ? "SUCCESS" : null, |
|
|
getTopicsTransactionState: null, |
|
|
getTopicsTransactionState: null, |
|
|
getPostsTransactionState: null, |
|
|
getPostsTransactionState: null, |
|
|
topicIDs: [], |
|
|
topicIDs: [], |
|
@ -58,7 +70,7 @@ class Profile extends Component { |
|
|
numberOfTopics={this.state.topicIDs.length} |
|
|
numberOfTopics={this.state.topicIDs.length} |
|
|
numberOfPosts={this.state.postIDs.length} |
|
|
numberOfPosts={this.state.postIDs.length} |
|
|
dateOfRegister={this.state.dateOfRegister} |
|
|
dateOfRegister={this.state.dateOfRegister} |
|
|
self/> |
|
|
self={this.profile.self}/> |
|
|
<div className="pure-u-1-1 profile-tabs-header"> |
|
|
<div className="pure-u-1-1 profile-tabs-header"> |
|
|
<p onClick={() => (this.handleTabClick("topics"))} |
|
|
<p onClick={() => (this.handleTabClick("topics"))} |
|
|
className={this.state.viewSelected === "topics" ? "profile-tab-selected" : ""}> |
|
|
className={this.state.viewSelected === "topics" ? "profile-tab-selected" : ""}> |
|
@ -88,6 +100,25 @@ class Profile extends Component { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
componentWillReceiveProps() { |
|
|
componentWillReceiveProps() { |
|
|
|
|
|
if (this.state.getUsernameTransactionState === null){ |
|
|
|
|
|
if (this.drizzle.contracts[contract]){ //Waits until drizzle is initialized
|
|
|
|
|
|
this.usernameKey = this.drizzle.contracts[contract] |
|
|
|
|
|
.methods[contractMethods.getUsername].cacheCall(this.state.userAddress); |
|
|
|
|
|
this.setState({'getUsernameTransactionState': "IN_PROGRESS"}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (this.state.getUsernameTransactionState === "IN_PROGRESS") { |
|
|
|
|
|
let currentDrizzleState = this.drizzle.store.getState(); |
|
|
|
|
|
let dataFetched = (currentDrizzleState |
|
|
|
|
|
.contracts[contract][contractMethods.getUsername])[this.usernameKey]; |
|
|
|
|
|
if (dataFetched){ |
|
|
|
|
|
this.setState({ |
|
|
|
|
|
'username': dataFetched.value, |
|
|
|
|
|
'getUsernameTransactionState': "SUCCESS" |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (this.state.getDateOfRegisterTransactionState === null){ |
|
|
if (this.state.getDateOfRegisterTransactionState === null){ |
|
|
if (this.drizzle.contracts[contract]){ //Waits until drizzle is initialized
|
|
|
if (this.drizzle.contracts[contract]){ //Waits until drizzle is initialized
|
|
|
this.dateOfRegisterKey = this.drizzle.contracts[contract] |
|
|
this.dateOfRegisterKey = this.drizzle.contracts[contract] |
|
|