diff --git a/src/components/Post.js b/src/components/Post.js index 9980c6f..242e7d3 100644 --- a/src/components/Post.js +++ b/src/components/Post.js @@ -1,4 +1,5 @@ import React from 'react'; +import { Link, withRouter } from 'react-router'; import UserAvatar from 'react-user-avatar'; import TimeAgo from 'react-timeago'; import ReactMarkdown from 'react-markdown'; @@ -9,11 +10,14 @@ const Post = (props) => { ?
{props.post.username}
@@ -60,4 +64,4 @@ const Post = (props) => {
);
};
-export default Post;
\ No newline at end of file
+export default withRouter(Post);
\ No newline at end of file
diff --git a/src/components/PostList.js b/src/components/PostList.js
index 5ff4099..d8bc25f 100644
--- a/src/components/PostList.js
+++ b/src/components/PostList.js
@@ -1,6 +1,5 @@
import { drizzleConnect } from 'drizzle-react';
import React, { Component } from 'react';
-import { Link } from 'react-router';
import PropTypes from 'prop-types';
import Post from './Post';
@@ -45,12 +44,15 @@ class PostList extends Component {
const posts = this.postsData.map((post, index) => {
if (post) {
return (
- {
+ this.context.router.push("/topic/" + post[4] + "/" +
+ ((this.orbitPostsData[index] !== undefined)
+ ? this.orbitPostsData[index].subject + "/" + this.props.postIDs[index]
+ : ""))}}
key={index}>
(this.handleTabClick("topics"))} className={this.state.viewSelected === "topics" ? "profile-tab-selected" : ""}> @@ -88,6 +100,25 @@ class Profile extends Component { } 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.drizzle.contracts[contract]){ //Waits until drizzle is initialized this.dateOfRegisterKey = this.drizzle.contracts[contract] diff --git a/src/containers/StartTopicContainer.js b/src/containers/StartTopicContainer.js index 2601b1b..3f1edf5 100644 --- a/src/containers/StartTopicContainer.js +++ b/src/containers/StartTopicContainer.js @@ -235,6 +235,8 @@ class StartTopic extends Component { 'savingToOrbitDB': null, 'transactionOutputTimerActive': false }); + this.props.router.push("/topic/" + this.topicIDFetched + "/" + + this.state.topicSubjectInput); }, 5000); } else if (this.state.savingToOrbitDB === "ERROR"){ diff --git a/src/containers/TopicContainer.js b/src/containers/TopicContainer.js index 9bd1a46..bdb2e2c 100644 --- a/src/containers/TopicContainer.js +++ b/src/containers/TopicContainer.js @@ -14,6 +14,10 @@ class Topic extends Component { constructor(props, context) { super(props); + if (!/^[0-9]+$/.test(this.props.params.topicId)){ + this.props.router.push("/404"); + } + this.fetchTopicSubject = this.fetchTopicSubject.bind(this); this.handleClick = this.handleClick.bind(this); this.postCreated = this.postCreated.bind(this); @@ -21,21 +25,25 @@ class Topic extends Component { 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, - topicSubject: null + posting: false }; } - async fetchTopicSubject(orbitDBAddress, topicID) { - /*const fullAddress = this.topicsData[topicID][1]; + 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(topicID)); - this.topicsSubjects[topicID] = som['subject']; - this.topicsSubjectsFetchStatus[topicID] = "fetched";*/ + 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(JSON.stringify(topicID)); + var som =this.props.orbitDB.topicsDB.get(JSON.stringify(this.state.topicID)); this.setState({'topicSubject': som['subject']}); } @@ -65,7 +73,7 @@ class Topic extends Component { topicContents = ( (