diff --git a/contracts/Forum.sol b/contracts/Forum.sol index 7d9c5e3..8fc94e9 100644 --- a/contracts/Forum.sol +++ b/contracts/Forum.sol @@ -41,6 +41,7 @@ contract Forum { } function getUsername(address userAddress) public view returns (string) { + require (hasUserSignedUp(userAddress), "User hasn't signed up yet."); return users[userAddress].username; } diff --git a/src/components/Post.js b/src/components/Post.js index 242e7d3..21ecbe2 100644 --- a/src/components/Post.js +++ b/src/components/Post.js @@ -1,67 +1,117 @@ -import React from 'react'; +import React, { Component } from 'react'; import { Link, withRouter } from 'react-router'; -import UserAvatar from 'react-user-avatar'; +import { drizzleConnect } from 'drizzle-react'; +import PropTypes from 'prop-types'; + import TimeAgo from 'react-timeago'; +import epochTimeConverter from '../helpers/EpochTimeConverter' +import UserAvatar from 'react-user-avatar'; import ReactMarkdown from 'react-markdown'; -const Post = (props) => { - return ( - props.post !== null - ?
-
- {props.post.username}
-
- Subject: {props.post.subject}
-
-
+
+
+ {this.props.blockchainData[0].returnData !== null
+ ?this.props.blockchainData[0].returnData[2]
+ :"Username"
+ }
+
+
+
+ Subject: {this.orbitPostData.subject}
+
+
+
Post content...
+ }Post content...
- } -- Subject -
-Post content...
-- Username: {props.username} -
-- Account address: {props.address} -
-- OrbitDB: {props.orbitAddress} -
-- Number of topics created: {props.numberOfTopics} -
-- Number of posts: {props.numberOfPosts} -
- {props.dateOfRegister && -- Member since: {props.dateOfRegister} -
- } - {props.self &&+ Username: {username} +
++ Account address: {props.address} +
++ OrbitDB: {orbitDBId} +
++ Number of topics created: {props.numberOfTopics} +
++ Number of posts: {props.numberOfPosts} +
++ Member since: {epochTimeConverter(dateOfRegister)} +
+ {props.self &&- {props.topic.topicSubject ? props.topic.topicSubject : "Subject"} -
-{props.topic.topicStarter}
-Number of replies: {props.topic.numberOfReplies}
-Started
Subject
-Username
-Number of replies:
-Started
+class Topic extends Component { + constructor(props){ + super(props); + + this.fetchSubject = this.fetchSubject.bind(this); + + this.topicSubject = null; + this.topicSubjectFetchStatus = "pending"; + } + + async fetchSubject(topicID) { + this.topicSubjectFetchStatus = "fetching"; + + if (this.props.blockchainData[0].returnData[1] === this.props.user.address) { + let som = this.props.orbitDB.topicsDB.get(topicID); + this.topicSubject = som['subject']; + this.topicSubjectFetchStatus = "fetched"; + } else { + const fullAddress = "/orbitdb" + this.props.blockchainData[0].returnData[0] + "/topics"; + const store = await this.props.orbitDB.orbitdb.keyvalue(fullAddress); + + /*store.events.on('replicated', () => { + const result = store.iterator({ limit: -1 }).collect().map(e => e.payload.value) + console.log(result.join('\n')) + })*/ + + await store.load(); + let som = store.get(topicID); + this.topicSubject = som['subject']; + this.topicSubjectFetchStatus = "fetched"; + } + } + + render(){ + return ( + ++ {this.topicSubject !== null ? this.topicSubject : "Subject"} +
++ {this.props.blockchainData[0].returnData !== null + ?this.props.blockchainData[0].returnData[2] + :"Username" + } +
++ {"Number of replies: " + (this.props.blockchainData[0].returnData !== null + ?this.props.blockchainData[0].returnData[4].length + :"") + } +
+
+ Started {this.props.blockchainData[0].returnData !== null &&
+
(this.handleTabClick("topics"))} className={this.state.viewSelected === "topics" ? "profile-tab-selected" : ""}> @@ -81,117 +76,24 @@ class Profile extends Component { Posts